加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – TCPDF错误:无法创建输出文件

发布时间:2020-12-13 22:21:21 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试使用TCPDF和FPDI的组合生成pdf.这是我的代码. require_once('../tcpdf/tcpdf.php');require_once('../FPDI/fpdi.php');$fileName = '../sample.pdf';class PDF extends FPDI {/** * "Remembers" the template id of the imported page */var $_tpl
我正在尝试使用TCPDF和FPDI的组合生成pdf.这是我的代码.

require_once('../tcpdf/tcpdf.php');
require_once('../FPDI/fpdi.php');

$fileName = '../sample.pdf';

class PDF extends FPDI {
/**
 * "Remembers" the template id of the imported page
 */
var $_tplIdx;
var $numPages = 0;

/**
 * Draw an imported PDF logo on every page
 */
function Header() {

    global $fileName;

    if (is_null($this->_tplIdx)) {
        $this->setSourceFile($fileName);
        $this->_tplIdx = $this->importPage(1);
        $this->numPages = $this->setSourceFile($fileName);
    }
    $size = $this->useTemplate($this->_tplIdx);
}

function Footer() {
    // emtpy method body
}
}

// initiate PDF
$pdf = new PDF($fileName);
$pdf->setFontSubsetting(true);

// add a page
$pdf->AddPage();

// save file
$pdf->Output('output.pdf','F');

这里,最后一行$pdf->输出(‘output.pdf’,’F’);用于保存文件.但它没有用.当我只有$pdf-> Output()时,它在浏览器中显示pdf.

我试过$pdf->输出(‘output.pdf’,’D’);下载,它工作正常.似乎$pdf->输出(‘output.pdf’,’F’);只是没有工作,它显示错误TCPDF错误:无法创建输出文件:output.pdf.

注意:没有文件权限问题

任何人都可以指出这个问题.

解决方法

尝试把ob_clean();正好在$pdf->输出(‘output.pdf’,’F’);

ob_clean();

// save file
$pdf->Output('output.pdf','F');

如果那不行.比你需要设置这样的路径:

$pdf->Output('yourpath/output.pdf','F');

如果你不知道绝对路径试试这个:

$pdf->Output($_SERVER['DOCUMENT_ROOT'] . 'output.pdf','F');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读