Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that php cannot output a file

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you about how to solve the problem that php can not output files. The article is rich in content and analyzes and narrates for you from a professional point of view. I hope you can get something after reading this article.

Php can not output the file solution: 1, add "ob_clean ();"; 2, set "$pdf- > Output ('yourpath/output.pdf',' F');"; 3, set "Output ($_ SERVER ['DOCUMENT_ROOT']").

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

What if php cannot export the file?

Specific questions:

Php-TCPDF error: unable to create output file

I'm trying to use a combination of TCPDF and FPDI to generate pdf. This is my code.

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 tplIdx;var * * 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')

Here, the last line $pdf- > output ('output.pdf','F'); is used to save the file. But it doesn't work. When I only have $pdf- > Output (), it displays pdf in the browser.

I tried $pdf- > output ('output.pdf','D'); download, it works fine. It seems that $pdf- > output ('output.pdf','F'); it just doesn't work, it shows error TCPDF error: unable to create output file: output.pdf.

Note: there is no file permission problem

Anyone can point out the problem.

Solution:

Try putting ob_clean (); just at $pdf- > output ('output.pdf','F')

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

If that doesn't work. Than you need to set this path:

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

If you don't know the absolute path, try this:

$pdf- > Output ($_ SERVER ['DOCUMENT_ROOT']. 'output.pdf',' F')

The above is the editor for you to share how to solve the php can not output files, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report