Fpdf16正在使用localhost但是当我在000webhost上传时无效

时间:2017-09-22 06:16:39

标签: php fpdf

我的PHP代码就是这个

    <?php
require_once('lib/fpdf16/fpdf.php');
/**
 * Class PDF
 */

require('Functions.php');
$function = new Functionality();

class PDF extends FPDF
{
    /**
     *
     */
    /*function Header()
    {
        if(!empty($_FILES["file"]))
        {
            $uploaddir = "image/logo.jpg";
            $nm = $_FILES["file"]["name"];
            $random = rand(1,99);
            move_uploaded_file($_FILES["file"]["tmp_name"], $uploaddir.$random.$nm);
            $this->Image($uploaddir.$random.$nm,10,10,20);
            unlink($uploaddir.$random.$nm);
        }
        $this->SetFont('Arial','B',12);
        $this->Ln(1);
    }
    function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('Arial','I',8);
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    }*/

    /**
     * @param $num
     * @param $label
     */
    /*function ChapterTitle($num, $label)
    {
        $this->SetFont('Arial','',12);
        $this->SetFillColor(200,220,255);
        $this->Cell(0,6,"$num $label",0,1,'L',true);
        $this->Ln(0);
    }*/

    /**
     * @param $num
     * @param $label
     */
    /*function ChapterTitle2($num, $label)
    {
        $this->SetFont('Arial','',12);
        $this->SetFillColor(249,249,249);
        $this->Cell(0,6,"$num $label",0,1,'L',true);
        $this->Ln(0);
    }*/
}

/**
 * Handle download tweet in pdf format request...
 */
if(isset($_REQUEST['download-pdf'])){
    ob_clean();
    $filename='image/temp.pdf';
    $screen_name = $_REQUEST['username'];
    $tweets = $function->generatePDFTweet($screen_name);
    $columns = array(array("name" => "Tweets","width" => 190));
    $pdf = new PDF();
    $pdf->AddPage();
    //Heading
    $pdf->SetFont('Times','',20);
    $pdf->SetTextColor(30);
    $pdf->Cell(0,3,$screen_name."'s tweet",0,1,'C');
    $pdf->Ln();
    $pdf->SetFillColor(232, 232, 232);
    $pdf->SetFont('Arial', 'B', 8);
    foreach ($columns as $column)
    {
        $pdf->Cell($column['width'], 6, strtoupper($column['name']), 1, 0, 'L', 1);
    }
    $pdf->Ln();
    $pdf->Ln();
    $pdf->SetFont('Arial', '', 10);
    foreach ($tweets as $tweet)
    {
        foreach ($columns as $column)
        {
            $pdf->MultiCell($column['width'], 6,$tweet['no'].'->'.$tweet['text'], 1);
        }
    }
    $pdf->Output($filename,'F');
    header("Content-type: application/pdf");
    header("Content-Disposition: attachment; filename=".$screen_name."'s tweet.pdf");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    readfile($filename);
    //unlink($filename);
    exit;
}
?>

Fpdf16正在使用localhost但是当我上传 000webhost 时无效 这段代码有什么问题?它完全在本地主机上运行。为什么它不在 000webhost 上运行 我该怎么办?我尝试了许多不同的选项,改变PHP版本所有这一切,但它无法正常工作。 错误显示如下。

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�mP�N�0��+�Ht�#΃B��7�%�nj�i`�T�{� ����1;��F*�n2ӸYpF�A�`�'`�y� ��` % 9�$ �5.C�b��n���Pqgm��~�����o��o�|T9I��HII(���1�1o1���/��Ry8B?��z9��%8;H)�?e�HqTX��\�)�ǝqB��88gB���`�M�4��������[ho:[�f��4���b�~"��G�Q��wJoMt��i�p��o�̣OW�������Ĭ\墳��_}�~� endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R /F2 6 0 R /F3 7 0 R >> /XObject << >> >> endobj 8 0 obj << /Producer (FPDF 1.6) /CreationDate (D:20170922060509) >> endobj 9 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 10 0000000000 65535 f 0000000442 00000 n 0000000824 00000 n 0000000009 00000 n 0000000087 00000 n 0000000529 00000 n 0000000627 00000 n 0000000728 00000 n 0000000948 00000 n 0000001023 00000 n trailer << /Size 10 /Root 9 0 R /Info 8 0 R >> startxref 1126 %%EOF

1 个答案:

答案 0 :(得分:0)

PDF的正确mime类型应为application/pdf

header('Content-type: application/pdf');