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);
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.