Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 复制TCPDF的示例6。获取错误“;没有这样的文件或目录;用于图像文件_Php_Tcpdf - Fatal编程技术网

Php 复制TCPDF的示例6。获取错误“;没有这样的文件或目录;用于图像文件

Php 复制TCPDF的示例6。获取错误“;没有这样的文件或目录;用于图像文件,php,tcpdf,Php,Tcpdf,我试图制作TCPDF的示例6:WriteHTML() 这就是我得到的错误 A PHP Error was encountered Severity: Warning Message: imagecreatefrompng(images/logo_example.png): failed to open stream: No such file or directory 这是我的view/application/views/reporte_pog.php的代码 <?php // c

我试图制作TCPDF的示例6:WriteHTML()

这就是我得到的错误

A PHP Error was encountered

Severity: Warning

Message: imagecreatefrompng(images/logo_example.png): failed to open stream: 
No such file or directory
这是我的view/application/views/reporte_pog.php的代码

<?php

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 006');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 006', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('dejavusans', '', 10);

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

// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)



// create some HTML content
$html = '<h1>HTML Example</h1>
Some special characters: &lt; € &euro; &#8364; &amp; è &egrave; &copy; &gt; \\slash \\\\double-slash \\\\\\triple-slash
<h2>List</h2>
List example:
<ol>
    <li><img src="images/logo_example.png" alt="test alt attribute" width="30" height="30" border="0" /> test image</li>
    <li><b>bold text</b></li>
    <li><i>italic text</i></li>
    <li><u>underlined text</u></li>
    <li><b>b<i>bi<u>biu</u>bi</i>b</b></li>
    <li><a href="http://www.tecnick.com" dir="ltr">link to http://www.tecnick.com</a></li>
    <li>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.<br />Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</li>
    <li>SUBLIST
        <ol>
            <li>row one
                <ul>
                    <li>sublist</li>
                </ul>
            </li>
            <li>row two</li>
        </ol>
    </li>
    <li><b>T</b>E<i>S</i><u>T</u> <del>line through</del></li>
    <li><font size="+3">font + 3</font></li>
    <li><small>small text</small> normal <small>small text</small> normal <sub>subscript</sub> normal <sup>superscript</sup> normal</li>
</ol>
<dl>
    <dt>Coffee</dt>
    <dd>Black hot drink</dd>
    <dt>Milk</dt>
    <dd>White cold drink</dd>
</dl>
<div style="text-align:center">IMAGES<br />
<img src="images/logo_example.png" alt="test alt attribute" width="100" height="100" border="0" /><img src="images/tcpdf_box.svg" alt="test alt attribute" width="100" height="100" border="0" /><img src="images/logo_example.jpg" alt="test alt attribute" width="100" height="100" border="0" />
</div>';

// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');


//Close and output PDF document
$pdf->Output('example_006.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+
?>

图像文件夹位于applications/libraries/tcpdf/examples/images中


我已经尝试了TCPDF网页中的其他示例,它们都很有效,比如为页眉和页脚创建自定义函数。我已经尝试使用images文件夹的完整路径,但也不起作用。

您应该将图像从代码的应用程序端移到更公开的级别

一般来说,人们将他们的公共资产,即Imgs/Js/Css存储在底层

例如
/var/www/html/site/assets/images/
这意味着在引用您的资产时,您只需使用
/images/logo\u example.png
,而不是希望/担心这些资产相对于您正在运行的脚本是否位于正确的位置

这还意味着,当向公众提供此代码时,您可以保护您的应用程序代码不受任何直接访问,同时仍然允许访问资产

因此,简而言之,将图像从脚本移动到基本
/var/www/html/site/assets/images/
,而不是:

 <img src="images/logo_example.png">


进行更改后,您将不再出现丢失图像错误。TCPDF目前显然只是找错了地方


最重要的是,我刚才说的,这对将来可能拿起你的代码的人来说也是非常有帮助的,因为他们知道所有资产都在一个地方,而不是在目录中寻找它们。当你忘记把它们放在哪里的时候,它甚至可能在几个月后对你有益

谢谢,我解决了这个问题。这是真的,我认为把我所有的照片和同意都放在一个地方肯定更好。
 <img src="./assets/images/logo_example.png">