vendredi 9 février 2018

Laravel PHP - upload_max_filesize ignored when trying to upload file

I have an app with Laravel in my own server. I've built a page with an input file upload and my server is configured to accept a max file size of 1MB. When I send the request to my controller, the upload starts and returns a OK 200 status even if the file is lower or greater than 1MB.

I've configured my php.ini with these settings:

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 1M


; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 500M

If the file is greater than 500MB or all the uploaded files are greater than 500MB I get a PostTooLargeException. I don't know if it is something related with Laravel or with my PHP, but I've tested multiple values in the upload_max_filesize config, restarting the HTTPD service daemon each time I applied the config and still not working.

I cannot find any information about it referencing Laravel bugs/errors or even PHP bugs/errors.

A phpinfo() call shows the information correctly, but it is not working. My example code is as follows:

<html>
<body>
...
    <div class="col-sm-8 col-xs-12">
        <div>
            <input type="file" id="file-upload" name="file-upload" />
        </div>
    <div class="col-sm-4 col-xs-12">
        <div>
            <button type="button" class="btn btn-success" data-toggle="fileUpload">Upload</button>
        </div>
    </div>
...
<script>
$('*[data-toggle="fileUpload"]').on('click', function() {
    var file = $('#file-upload[name="file-upload"]').prop('files')[0];
    var formData = new FormData();
    formData.append('file', file);
    formData.append('_token', $('meta[name="csrf-token"]').attr('content'));
    $.ajax({
        url: '/upload',
        method: 'POST',
        dataType: 'json',
        contentType: false,
        processData: false,
        cache: false,
        data: formData,
        success: function(data, jqXHR, status) {
            console.log(data);
        },
        error: function(jqXHR, status, error) {
            console.log(error);
        },
    });
});
</script>
</body>
</html>

The server side controller code has nothing, only a return true;

Let me know if you need any further information.

Current setup: Laravel 5.4, PHP 7.0

Best regards, D.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire