Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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!

share|improve this question
1  
try post_max_size = 20M also check if your configurations are being used phpinfo() – bansi yesterday
    
Yup, that was it. Can't believe something this small caused me so much trouble. Thanks friend :) – user2884505 yesterday
up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.