Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_get_contents('php://input'); returns empty string with large files [duplicate]

Tags:

javascript

php

I'm trying to save Files on my Server. It works perfect with small files but not with large ones.

In JavaScript I'm sending the files with a XMLHttpRequest as follows

var ajax = new XMLHttpRequest();
ajax.open('POST', configuration.backend + 'ajax/uploadVideo', true);
ajax.setRequestHeader('X-File-Name', input.files[0].name);
ajax.setRequestHeader('X-File-Size', input.files[0].size);
ajax.send(input.files[0]);

in PHP this script saves the input to the harddrive:

$filename = $_SERVER['HTTP_X_FILE_NAME'];
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$new_filename = uniqid().'.'.$extension; 
$fh = fopen(DOCROOT.'/public/videos/'.$new_filename, 'w');
fwrite($fh, file_get_contents('php://input'));
fclose($fh);

The script works perfectly with smaller files, but not with larger ones. It just creates a file with 0 Bytes. (8.7MB ist not working while 5.7MB works). I don't get any PHP errors. Error reporting level is E_ALL & ~E_DEPRECATED.

I've also tried to increase the values of post_max_size, upload_max_filesize and memory_limit, but no change made any effect.

like image 265
Andreas Schrottenbaum Avatar asked Sep 18 '26 09:09

Andreas Schrottenbaum


1 Answers

Just found the error. It was post_max_size to change in the php.ini (not just with ini_set()), not the upload_max_filesize.

like image 103
Andreas Schrottenbaum Avatar answered Sep 19 '26 22:09

Andreas Schrottenbaum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!