Php: // error with large files

I use a script download with ajax and PHP, and it works wonders for files smaller than 80 MB. However, if the file is larger than 80 MB, it does not work, it does not even output anything.

The code:

$maxsize = getMaxFileSize();
$finalfile = $uploadpath . $finalname;
$putdata = fopen("php://input", "r");
$fp = fopen($finalfile, "w");
$filesizecalc = 0;
while ($data = fread($putdata, 1024)) {
    fwrite($fp, $data);
    $filesizecalc = $filesizecalc + 1024;
}

fclose($fp);
fclose($putdata);
if ($filesizecalc <= $maxsize) {
    addFile($_SESSION['userdata']['userid'], $finalname);
    echo "$fn uploaded";
} else {
    unlink($finalfile);
}
exit();

This works fine with almost all files <80 MB, but for files larger than 80 MB it does not display anything, so I don’t even know what will go wrong, although I installed

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
ini_set('memory_limit', '1024M');
ini_set('upload_max_filesize', '1024M');
ini_set('post_max_size', '1024M');
ini_set('max_input_time', 10000);
ini_set('max_execution_time', 10000);
+3
source share
1 answer

Allows you to write it as a solution so that you can read it correctly, and not dig in the comments.

  • php_info() ini_set, script, ~ 6 , . ( )
  • apache error_log . ( access_log, , ).
  • apache, . , " reset".

W3Scools script:

<?php
if (true)
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?> 
+3

All Articles