无法使用PHP

时间:2019-05-24 07:35:58

标签: php http download fpdf

我正在尝试使用PHP从目录下载pdf文件,但无法发生。我在下面提供我的代码:

if (count($data) > 0) {
            $pdf = new PDF();
            //$pdf = new FPDF(); 
            //header
            $pdf->AddPage();
            $width_cell=array(15,30,40,40,35,25);
            $pdf->SetFont('Arial','B',12);
            $pdf->SetFillColor(193,229,252);
            $pdf->Cell($width_cell[0],10,'Sl No',1,0,C,true);
            $pdf->Cell($width_cell[1],10,'Owner Name',1,0,C,true);
            $pdf->Cell($width_cell[2],10,'Date',1,0,C,true);
            $pdf->Cell($width_cell[3],10,'Booking ID',1,0,C,true);
            $pdf->Cell($width_cell[4],10,'Operator Total',1,0,C,true);
            $pdf->Cell($width_cell[5],10,'Ride Total',1,1,C,true);
            $pdf->SetFont('Arial','',10);
            //Background color of header//
            $pdf->SetFillColor(235,236,236); 
            //to give alternate background fill color to rows// 
            $fill=false;
            foreach ($data as $row) {
                $pdf->Cell($width_cell[0],10,$row['sl_no'],1,0,C,$fill);
                $pdf->Cell($width_cell[1],10,$row['owner_name'],1,0,L,$fill);
                $pdf->Cell($width_cell[2],10,$row['last_update'],1,0,C,$fill);
                $pdf->Cell($width_cell[3],10,$row['book_id'],1,0,C,$fill);
                $pdf->Cell($width_cell[4],10,$row['operator_total'],1,0,C,$fill);
                $pdf->Cell($width_cell[5],10,$row['ride_total'],1,1,C,$fill);
                $fill = !$fill;
            }

            $today = date('YmdHi');
            $filename='report_'.$today.'.pdf';
            $totalpath='/var/www/hlwcab.com/public_html/cab/service/admin/report/download/'.$filename;
            $pdf->Output($totalpath, "F");
            //$pdf->Output($filename,"D");
            header('Content-Description: File Transfer');
            header("Content-type: application/pdf");
            header('Content-Disposition: attachment; filename='.basename($totalpath));
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($totalpath));
            ob_clean();
            flush();
            readfile($totalpath);
            $result1["msg"] = "Succesfully Downloaded...";
        }else{
            header("HTTP/1.0 401 Unauthorized");
            $result1["msg"] = "No record to download...";
        }

在这里,我正在创建PDF文件,并在保存到内部目录后尝试下载,但没有文件在浏览器上下载。我需要在浏览器中从目录下载文件。

0 个答案:

没有答案