致命错误:找不到“TCPPDF"类 [英] Fatal error: Class 'TCPDF' not found

查看:93
本文介绍了致命错误:找不到“TCPPDF"类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成 PDF 文件,但遇到了问题.谁能告诉我这个错误的解决方案.下面是我为此使用的代码.我为此包含了 tcpdf,但有一个致命错误,说 tcpdf 文件不可用,或者我们可以说找不到.

SetCreator(PDF_CREATOR);//设置一个文档信息包括(db_connection.php");$isql = mysqli_query($con, "SELECT * FROM `cpdf`") OR die("数据选择问题:".mysqli_error($con));$num = mysqli_num_rows($isql);$pdf->AddPage();//添加新页面while($row = mysqli_fetch_array($isql)){$firstname = $row['fname'];$lastname = $row['lname'];$fullname = $firstname ." ".$lastname;?><头><title>PDF页面</title><身体><表格><div><div><img style="width: 100%; height: 20%" src="image/FlZJRBAXRlweb design.idevtechnolabs.socialsigna.l.JPG"/></div><div style="宽度:100%;高度:30%"><table style="float: right; border: 2;"><tr style="width: 10%;"><td style="text-align: left;"><?php echo $fullname;?></td></tr><tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['add1'];?></td></tr><tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['add2'];?></td></tr><tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['city'];?></td></tr><tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['state'];?></td></tr><tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['date'];?></td></tr>

<div style="float: left; height: 10%;"><b>主题:</b><?php echo $row['subject'];?>

<div style="height: 40%; width: 100%;"><p style="text-align: justify;">嘿,<br/><br/><?php 先生 echo $fullname;?>.这是为了通知您后天是您发票付款的最后日期.这是支付您的 <?php echo $row['bill']; 的提醒通知.?>发票金额我们最近的商店,并利用我们的服务.</p><p style="text-align: justify; text-indent: 4em;">我们要求您支付 <?php echo $row['bill'];?>尽快结帐.

<span style="float: right;">谢谢,<br/><img src="#"/></span></div><?php $pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);}$pdf->Output('example_002.pdf', 'I');?>

</表单></html>

解决方案

作为第一步,注释掉前七行代码,并使用文件的完整路径添加一行包含 tcpdf.php 的新代码.如果这不起作用,那么您应该检查 tcpdf.php 文件的内容以确保它没有在途中的某个地方损坏.也就是说,确保它仍然包含声明 TCPDF 类的代码.

如果可行,然后注释掉硬编码的 include 语句,取消注释前面注释掉的七行,并添加一个 echo 语句以在该循环的每次迭代期间打印出 $tcpdf_include_path 变量.只要这些路径之一与可能较早使用的硬编码路径匹配,那么您的代码应该可以正常工作.

最后,我非常怀疑情况是否如此,但是如果您碰巧有一个区分大小写的文件系统,并且碰巧将 tcpdf.php 文件保存为 TCPPDF.PHP,那么这可能会导致问题.我只是提到了答案完整性的可能性,但极不可能,尤其是根据您提供的信息,这是您的情况的问题.

I am generating the PDF file but facing the trouble. Can anybody tell me the solution of this error. Below is the code that I used for that. I include the tcpdf for this but there is a fatal error that saying that tcpdf file in not available or we can say not found.

<?php
    $tcpdf_include_dirs = array(realpath('tcpdf.php'), '/usr/share/php/tcpdf/tcpdf.php', '/usr/share/tcpdf/tcpdf.php', '/usr/share/php-tcpdf/tcpdf.php', '/var/www/tcpdf/tcpdf.php', '/var/www/html/tcpdf/tcpdf.php', '/usr/local/apache2/htdocs/tcpdf/tcpdf.php');
    foreach ($tcpdf_include_dirs as $tcpdf_include_path) {
        if (@file_exists($tcpdf_include_path)) {
            require_once($tcpdf_include_path);
            break;
        }
    }

    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // Create New PDF Doc
    $pdf->SetCreator(PDF_CREATOR); //Setup a document information

    include("db_connection.php");       

    $isql = mysqli_query($con, "SELECT * FROM `cpdf`") OR die("Data Select problem: ".mysqli_error($con));
    $num = mysqli_num_rows($isql);

    $pdf->AddPage(); //Add new page

    while($row = mysqli_fetch_array($isql)){
        $firstname = $row['fname'];
        $lastname = $row['lname'];
        $fullname = $firstname ." ".$lastname;
        ?>
<html>
    <head>
        <title>PDF Page</title>
    </head>
    <body>
        <form>
            <div>
                <div><img style="width: 100%; height: 20%" src="image/FlZJRBAXRlweb design.idevtechnolabs.socialsigna.l.JPG"/></div>
                <div style="width: 100%; height: 30%">
                    <table style="float: right; border: 2;">
                        <tr style="width: 10%;"><td style="text-align: left;"><?php echo $fullname; ?></td></tr>
                        <tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['add1']; ?></td></tr>
                        <tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['add2']; ?></td></tr>
                        <tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['city']; ?></td></tr>
                        <tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['state']; ?></td></tr>
                        <tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['date']; ?></td></tr>
                    </table>
                </div>
                <div style="float: left; height: 10%;">
                    <b>Subject:</b> <?php echo $row['subject']; ?>
                </div>
                <div style="height: 40%; width: 100%;">
                    <p style="text-align: justify;">Hey, <br /><br /> Mr. <?php echo $fullname; ?>. This is to inform you that a day after tomorrow is the last date of your invoice payment. This is a reminder notice to pay your <?php echo $row['bill']; ?> invoice amount our nearest store and takes advantage of our services.</p>
                    <p style="text-align: justify; text-indent: 4em;">We request you to pay your <?php echo $row['bill']; ?> Bill as soon as possible.</p>
                    <span style="float: right;">Thank you,<br /><img src="#"/></span>
                </div><?php $pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0); 
                } 
                $pdf->Output('example_002.pdf', 'I'); ?>
            </div>
        </form>
    </body>
</html>

解决方案

As a first step, comment out the first seven lines of code and add one new line of code that includes tcpdf.php using the full path to the file. If that doesn't work then you should check the contents of the tcpdf.php file to make sure that it hasn't been corrupted somewhere along the way. That is, make sure it still contains the code that declares the TCPDF class.

If that works then comment out the hard-coded include statement, uncomment the seven lines that were commented out earlier and add an echo statement to print out the $tcpdf_include_path variable during each iteration of that loop. As long as one of those paths match the hard-coded path that presumably worked earlier, then your code should work fine.

Finally, and I highly doubt this is the case, but if you happened to have a case-sensitive file system and you happened to have the tcpdf.php file saved as TCPDF.PHP, for example, then that might contribute to the problem. I'm only mentioning that possibility for completeness to the answer, but it is highly unlikely, especially based on the information you provided, that this is the problem in your case.

这篇关于致命错误:找不到“TCPPDF"类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆