dongyuxiao6295 2015-10-30 16:29
浏览 32
已采纳

FPDF未将PDF保存在服务器中

Goodafternoon, I made this script but I can't get where I'm wrong, it didn't save the PDF as I tried to program. Thank you if there's any suggestion. I know the problem is in the logic inside: function file_newname but I don't know where exactly. Thank you in advance.

    <?php
require('fpdf.php');
class PDF extends FPDF{
    function Header(){
        $this->Image('img/oet.png',10,6,30);
        $this->SetFont('Helvetica','B',25);
        $this->Cell(55);
        $this->Cell(100,10,"TITLE",0,0,'C');
        $this->SetFont('Helvetica','B',18);
        $this->Ln(10);
        $this->Cell(55);
        $this->Cell(100,10,"SUBTITLE",0,0,'C');
        $this->Ln(20);
    }
    function Footer(){
        $this->SetY(-15);
        $this->SetFont('Times','I',8);
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    }
    function file_newname($filename){
        if($pos = strrpos($filename, '.')) {
            $name = substr($filename, 0, $pos);
            $ext = substr($filename, $pos);
        }else{
            $name = $filename;
        }
        $newpath = 'docs/'.$filename;
        $counter = 0;
        while (file_exists("docs/")) {
            $filename = $name .'_'. $counter . $ext;
            $newpath = "docs/".$filename;
            $counter++;
        }
        $this->Output("docs/".$filename);
    }
}


$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=10;$i++){
    $pdf->Cell(0,10,'Printing line number '.$i,0,1);
}
$pdf->Output();
$pdf->file_newname(date("Ymd").".pdf");
?>
  • 写回答

2条回答 默认 最新

  • dongxun1244 2015-10-30 17:29
    关注

    Here is the right solution:

    function file_newname($filename){
            if($pos = strrpos($filename, '.')) {
                $name = substr($filename, 0, $pos);
                $ext = substr($filename, $pos);
            }else{
                $name = $filename;
            }
            $newpath = 'documenti/'.$filename;
            $counter = 0;
            while (file_exists("documenti/".$filename)) {
                $filename = $name .'_'. $counter . $ext;
                $newpath = "documenti/".$newname;
                $counter++;
            }
            $this->Output("documenti/".$filename);
            $this->Output();
        }
    $pdf->file_newname(date("Ymd").".pdf");<<<<
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥200 求能开发抖音自动回复卡片的软件
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。