I'm using a upload script with ajax and PHP and it works wonders for files smaller than 80MB. However, if the file is bigger than 80MB it fails, it doesn't even output anything at all.
The code is:
$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 bigger than 80MB it doesn't output a thing, so I don't even know what's going wrong, even though I set
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);
Lets write it down as solution so it can be read correctly rather than digging in the comments.
Try the W3Scools upload 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";
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With