0

I had made a PHP file using fopen and fwrite and I am trying to execute that file but it's giving me

Internal Server Error

while making file I had to change the permission to 0775 using chmod

$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);

I want user can execute this file but while trying to execute this file I am getting an Internal Server Error.

Mac
  • 80
  • 7
vivek modi
  • 417
  • 3
  • 14
  • What is the error? what to the logs say? – Nick Maroulis Jan 28 '19 at 06:00
  • no error log has been generated in epub folder – vivek modi Jan 28 '19 at 06:02
  • Add `error_reporting(-1);` at the top of your file, then check the error-log. A 500 error can come from so many things. – Qirel Jan 28 '19 at 06:20
  • Possible duplicate of [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Magnus Eriksson Jan 28 '19 at 06:42
  • @Qirel still getting same output no change – vivek modi Jan 28 '19 at 07:03
  • 1
    Enabling error-reporting will not change the output, but it will ensure the logs are filled with the error. Find your `error.log` file in that folder and see what it contains. – Qirel Jan 28 '19 at 07:09
  • Partly unrelated, but is your file name: 829310_Revolution_Test_(5)-converted_(4).epub.php.php because you append .php to the end of a string that ends in .php which if you open a file that doesn't exist, you may get some errors with fopen (I don't remember, but I'm pretty sure it can't auto create) – Steve Byrne Jan 28 '19 at 07:50

1 Answers1

1

To know exact errors you should turn on the error reporting by adding following lines at the top of your php file:

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

For more info on error reporting, check this page.

Once you get exact error, you can easily debug the server error.

Mac
  • 80
  • 7