【问题标题】:How to fix '500 Internal Server Error' while file handling?如何在文件处理时修复“500 内部服务器错误”?
【发布时间】:2019-01-28 05:51:21
【问题描述】:

我使用 fopen 和 fwrite 制作了一个 PHP 文件,我正在尝试执行该文件,但它给了我

内部服务器错误

在制作文件时,我必须使用 chmod 将权限更改为 0775

$book="829310_Revolution_Test_(5)-converted_(4).epub.php";  
$book=str_replace(" ","_",$book);
$path=$book.".php";
$myfile =fopen("../../include/uploaded/epub/$path", "w") or die("Unable to open file!");
$txt = "<?php include('hello.php'); ?>";
fwrite($myfile, $txt);
fclose($myfile);
chmod("../../include/uploaded/epub/$book", 0775);
chmod("../../include/uploaded/epub/$path", 0775);

我希望用户可以执行此文件,但在尝试执行此文件时出现内部服务器错误。

【问题讨论】:

  • 错误是什么?日志怎么说?
  • epub文件夹中没有生成错误日志
  • 在文件顶部添加error_reporting(-1);,然后检查错误日志。 500 错误可能来自很多方面。
  • 启用错误报告不会改变输出,但会确保日志充满错误。在该文件夹中找到您的 error.log 文件并查看其中包含的内容。

标签: php file-handling


【解决方案1】:

要知道确切的错误,您应该通过在 php 文件顶部添加以下行来打开错误报告:

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

有关错误报告的更多信息,check this page

一旦得到确切的错误,您就可以轻松调试服务器错误。

【讨论】:

  • 仍然得到相同的输出没有变化
  • 这应该是评论,而不是答案。
猜你喜欢
  • 2019-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多