【问题标题】:php code for creating .pdf file is not working on server用于创建 .pdf 文件的 php 代码在服务器上不起作用
【发布时间】:2012-01-04 09:31:04
【问题描述】:

我正在使用 PHP 代码创建 .pdf 文件,并在该 .pdf 文件中归档表单值。

在本地主机上,代码运行良好,它创建 .pdf ,编辑 .pdf 文件 .... 但是当我将相同的代码放在另一台服务器上时,它不会创建 .pdf 并编辑到......

代码是-

<?php
date_default_timezone_set('UTC');
require('fpdf/fpdf.php');

class PDF_result extends FPDF {
    function __construct ($orientation = 'P', $unit = 'pt', $format = 'Letter', $margin = 5 ) {
        $this->FPDF($orientation, $unit, $format);
        $this->SetTopMargin($margin);
        $this->SetLeftMargin($margin);
        $this->SetRightMargin($margin);
        //$this->SetRightMargin1($margin1);
        $this->SetAutoPageBreak(true, $margin);
    }

    function Header () {
        //$this->SetLeftMargin(85);
        $this->SetLeftMargin(5);
         $this->Image('header3.jpg',25,15,560);
         $this->SetLeftMargin(25);
    //  $this->SetFont('Arial', 'B', 20);
    //  $this->SetFillColor(36, 96, 84);
    //  $this->SetTextColor(225);
    //  $this->Cell(0, 30, "YouHack MCQ Results", 0, 1, 'C', true);
    }

 function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',8);
    //Page number
    $this->Cell(0,10,'ifs , india',0,0,'C');
}


function Generate_Table($subjects, $marks) {
    $this->SetFont('Arial', 'B', 12);
    $this->SetTextColor(0);
//  $this->SetFillColor(94, 188, z);
$this->SetFillColor(94, 188, 225);
    $this->SetLineWidth(1);
    $this->Cell(427, 25, "Subjects", 'LTR', 0, 'C', true);
    $this->Cell(100, 25, "Marks", 'LTR', 1, 'C', true);

    $this->SetFont('Arial', '');
    $this->SetFillColor(238);
    $this->SetLineWidth(0.2);
    $fill = false;

    for ($i = 0; $i < count($subjects); $i++) {
        $this->Cell(427, 20, $subjects[$i], 1, 0, 'L', $fill);
        $this->Cell(100, 20,  $marks[$i], 1, 1, 'R', $fill);
        $fill = !$fill;
    }
    $this->SetX(367);
    //$this->Cell(100, 20, "Total", 1);
//  $this->Cell(100, 20,  array_sum($marks), 1, 1, 'R');
}

}

(代码不完整)

具体的问题是什么?

【问题讨论】:

  • 您收到的确切错误/输出/警告/消息是什么?
  • ftp 不是服务器,它是传输文件的协议
  • 请注意您的服务器上启用了错误记录和报告(检查您的 php.ini 配置),然后查看错误日志。它应该告诉你出了什么问题。
  • @Arfeen :我没有收到任何错误或警告,只是没有找到浏览器回复文件,这意味着 .pdf 文件。
  • @Dagon 无论其协议或服务器如何,关键是解决方案是什么? :)

标签: php javascript pdf-generation fpdf


【解决方案1】:

如果此代码在本地主机上运行,​​则可能是您的服务器上的权限问题。

【讨论】:

    【解决方案2】:

    检查您的 apache 错误日志。它通常位于/var/log/apache/error.log

    如果您已登录到您的服务器,请输入

    tail -f /var/log/apache/error.log
    

    然后重新加载页面——任何错误都会显示在这里。如果您需要帮助诊断它们,请将它们粘贴到此处

    【讨论】:

      【解决方案3】:

      似乎是权限问题。在预期创建 pdf 文件的目录上设置权限。

      【讨论】:

        猜你喜欢
        • 2023-03-25
        • 2016-09-18
        • 2016-05-08
        • 1970-01-01
        • 2012-08-17
        • 1970-01-01
        • 2014-10-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多