Cannot load files larger than 50 KB using AJAX

I am not sure why my code below does not process files larger than 50 KB on my hosting, although I work perfectly on the local host.

I tested a lot of different file sizes, and I'm sure 50kb is its limit. If the file is larger than 50 KB, it will never be transferred to process.php. If the file is less than 50 KB, it will be transferred to process.php ok.

Can anyone help me fix this. I am stuck with this problem for hours.

I set upload_max_filesize in php.ini to 5M.

 $( document ).ready(function() { $('#img_uploader').on('change', function() { uploadFiles(this.files); } }); function uploadFiles(fileList) { var xhr = new XMLHttpRequest(); var formData = new FormData(); for (var i = 0; i < fileList.length; i++) { var file = fileList[i]; if (!file.type.match('image.*')) { continue; } formData.append('photos[]', file); formData.append('request', "uploadImg"); } xhr.open('POST', 'process.php', true); xhr.onload = function () { if (xhr.status === 200) { var data = xhr.responseText; console.log(data); //convert_json_append_HTML(data); } else { alert('An error occurred!'); } }; xhr.send(formData); } 

Updated: Test Results

I spent 6 hours to find the problem.

It really is connected.

1/4 hours to view all Javascript and PHP code, write down each step to make sure nothing happened to the code.

  • Tested on localhost with all scripts. It worked great.

2 / Changed these three variables did not fix the problem, no matter what limit I set. Therefore, I changed them to standard ones.

  • upload_max_filesize
  • memory_limit
  • post_max_size

3 / Browser test:

2 files created: test_1.php and test_2.php. (basic HTML, no Javascript involved)

test_1.php

 <form action="test2.php" method="post" enctype="multipart/form-data"> Select image to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload Image" name="submit"> </form> 

test_2.php

 <?php var_dump($_FILES); 

HTTP

Chrome:

  • Files <50kb: passed
  • Files> 50kb: passed

Firefox:

  • Files <50kb: passed
  • Files> 50kb: passed

Internet Explorer:

  • Files <50kb: passed
  • Files> 50kb: passed

Https

Chrome:

  • Files <50kb: passed
  • Files> 50kb: failed

Firefox:

  • Files <50kb: passed
  • Files> 50kb: passed

Internet Explorer:

  • Files <50kb: passed
  • Files> 50kb: passed

I am not sure why a file larger than 50 KB cannot be transferred from test_1.php to test_2.php over HTTPS with Chrome. Does anyone here know the reason? Or you can try testing it on your own server.

+5
source share
2 answers

I understood the problem.

Kaspersky Internet Security automatically injects the script into any web pages downloaded using Chrome (IE and FF are not affected).

The script blocks any packet larger than 50 KB sent to the web server using the HTTPS protocol.

enter image description here

  • Solution: Kaspersky Internet Security> Settings> Advanced> Network>

    • Uncheck "Inject script in web traffic to interact with web pages"

enter image description here

+1
source

You need to set the desired values ​​for three variables Check this here

  • upload_max_filesize
  • memory_limit
  • post_max_size
+3
source

Source: https://habr.com/ru/post/1261765/


All Articles