user2884505 user2884505 - 14 days ago 9
PHP Question

PHP - $_FILES empty after large file upload on Azure

I've setup an Angular based file upload using the ng-file-upload plugin (https://github.com/danialfarid/ng-file-upload) and I've been handling the file upload with a PHP script.

The file upload and script work on smaller files (tested it on < 1MB), but fails on a larger file (9MB). This leads me to believe that there's a file upload issue. However, I've already created a .user.ini file in the /wwwroot folder with a single line:

upload_max_filesize=20M


Is there another reason why the $_FILES and $_POST arrays would be empty?

JS Code:

Upload.upload({
url: '/scripts/receiveFile.php',
file: file
}).then(function(resp) {
console.log(resp.data);
}, function(resp) {
console.log(resp.data);
}, function(evt) {
var progressPercent = parseInt(100.0 * evt.loaded / evt.total);
console.log(progressPercent + "%");
});


HTML Code:

<div>
<h1>Upload</h1>
<input type="file" accept=".zip" ngf-select="submitFile($file)"></input>
</div>


PHP Code:

$file_name = basename($_FILES['file']['name']);
$file_tmp_name = $_FILES['file']['tmp_name'];


The script fails because 'file' is undefined in the $_FILES array - because the $_FILES array is empty.

Thanks!

Answer

PHP has a confusing was of doing file uploads. To set a larger upload size, you should set both upload_max_filesize and post_max_size. These can be independently different values, as they do different things.

post_max_size is the maximum file size that can be sent in a POST request to the PHP script. upload_max_filesize is the maximum file size allowed via any method.