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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23488513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:45:41  来源:igfitidea点击:

mPDF error: Unable to create output file

phpmpdfhtml-to-pdf

提问by Fahad Khan

I am Using mPDFto generate pdf from an html.

我正在使用mPDF从 html 生成 pdf。

On my localhost the pdf is generated to the located directory successfully. But not on Server, although I have open the permissions of that directory.

在我的本地主机上,pdf 已成功生成到找到的目录中。但不是在服务器上,虽然我已经打开了那个目录的权限。

chmod -R 0777 /mydirectory

Found this commentfrom an answer and changed fopen($file_out,'wb');to fopen($file_out,'w+');in mpdf.php

从答案中找到 此评论并更改fopen($file_out,'wb');fopen($file_out,'w+');mpdf.php

But no success.

但没有成功。

Thanks for any help.

谢谢你的帮助。

回答by Nikola

Try not to modify the source. Instead, revert back to fopen($file_out,'wb');and make sure that folder permissions are set to 0777, like you did.

尽量不要修改源。相反,恢复到fopen($file_out,'wb');并确保文件夹权限设置为0777,就像您所做的那样。

Also, check if you're using the absolute pathin order to write to a file, rather than using relative paths or even worse, URL.

此外,请检查您是否使用绝对路径来写入文件,而不是使用相对路径或更糟糕的是 URL。

So,

所以,

$file = "/var/www/html/mywebsite/mypdfs/myfile.pdf";

$file = "/var/www/html/mywebsite/mypdfs/myfile.pdf";

and try if it works.

并尝试它是否有效。

Good luck!

祝你好运!