简体   繁体   English

内部服务器错误读取文件

[英]Internal Server Error readfile

I have a view-script which opens a pdf-file, it looks like follows: 我有一个可打开pdf文件的视图脚本,如下所示:

<?php
$this->title = 'arbeitskalender';
//ini_set('display_errors',1);
header('Content-Type:application/pdf');
header('Content-Disposition', 'attachment; fileName=arbeitskalender.pdf');
readfile('./pdfs/arbeitskalender.pdf');
?>

On my localhost (wamp-server) it works well and the file opens without any error, uploaded to my webspace (not my own server, only a webspace) I get 在我的本地主机(wamp-server)上,它运行良好,文件打开没有任何错误,并上传到我的网站空间(不是我自己的服务器,只有网站空间)

internal server error 内部服务器错误

.

What's the problem? 有什么问题? Is there a possibility to get a more informative error message? 是否有可能获得更详尽的错误消息? Because it is not my server, I can't have a look in the server log. 由于它不是我的服务器,因此无法查看服务器日志。

Yes, a lot of: 是的,很多:

  • check the network tab in your developer bar. 检查开发人员栏中的网络标签。 Eventually, turn off (starts the header lines with //) your headers in your script to see the error message (for debugging) 最终,关闭脚本中的标题(以//开头标题行)以查看错误消息(用于调试)
  • check the logfiles of your framework (if you use) 检查框架的日志文件(如果使用)
  • check if your application can write log entries 检查您的应用程序是否可以写入日志条目
  • enable and display errors (see Showing all errors and warnings ) 启用并显示错误(请参阅显示所有错误和警告
  • check if php can read the file (permissions and existing of the file) 检查php是否可以读取文件(权限和文件的存在)
  • check if you only get the internal server error on this page 检查是否仅在此页面上收到内部服务器错误

Looking to your script: 查看您的脚本:

  • what's $this? 这是什么? I don't see a class definition 我看不到课程定义
  • can php find the file? PHP可以找到文件?

Check ./pdfs/arbeitskalender.pdf permissions. 检查./pdfs/arbeitskalender.pdf权限。 I guess it's not readable for apache user 我想这对apache用户不可读

I checked all your suggestions, I learned some more, but couldn't solve the problem. 我检查了您的所有建议,了解了更多信息,但无法解决问题。 I found another codesnippet which doesn't use readfile and so far this works fine. 我发现了另一个不使用readfile代码片段,到目前为止,它工作正常。

<?php
require_once 'Zend/Pdf.php';

header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename=arbeitskalender.pdf');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');
echo file_get_contents("./pdfs/arbeitskalender.pdf");

?>
<html>
<body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM