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条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?