简体   繁体   中英

Error 500 while uploading images to the server

I build a CMS with PHP that has a gallery feature where you could select multiple images and upload it to the server. For the upload of the images i'm using a plugin called File-up, https://shabuninil.github.io/fileup/ , which lets you upload files to the server with ajax-requests. When multiple images are selected this plugin sends 1 (one) image per request, so if you select 5 images the plugin will send 5 ajax-requests to the server. On the server there is a script that takes the image sent by the plugin, it validates the image and moves it to a specific folder with the move_uploaded_file function.The issue is that somehow I get a 500 Error to some requests of the plugin. I've tried different posts about the 500 error posted here, stackoverflow.com, in order to fix the issue but with no success. I thought that maybe the server was getting too many requests at once from the plugin so I implemented Jquery's setTimeout() function with 5 seconds, but still no success.

I even thought that maybe the CMS had some bugs or something so I tested the CMS by placing it on another server at co.nf but on that server I didn't get any errors, everything worked fine, so if I'm right the issue is on the original server. I'm out of ideas, so, can anyone help me out? Thanks in advance!

The function that places the image into a specific folder, in this case the “upload” folder:

// Be sure we're dealing with an upload
if (is_uploaded_file($_FILES['filedata']['tmp_name']) === false) {
    throw new \Exception('Error on upload: invalid file definition');
}

// Rename uploaded file
$uploadName = $_FILES['filedata']['name'];
$ext        = strtolower(substr($uploadName, strripos($uploadName, '.') + 1));
$filename   = round(microtime(true)) . mt_rand() . '.' . $ext;
$target_dir = "../uploads/" . $filename;

if (move_uploaded_file($_FILES['filedata']['tmp_name'], $target_dir)) {
// Save filename into db
}

Image of the ajax-requests and their errors:

Error in the server's error file:

[Mon Nov 20 01:17:44 2017] [error] [client IP_ADDRESS ] [client IP_ADDRESS] 
ModSecurity: Warning. Match of "eq 0" against "MULTIPART_UNMATCHED_BOUNDARY" 
required. [file "/services/mod_security-rules/00_asl_zz_strict.conf"] [line 
"37"] [id "330792"] [rev "2"] [msg "Multipart parser detected a possible 
unmatched boundary. This may be an impedence mismatch attack, a broken 
application or a broken connection.  This is not a false positive.  Check 
your application or client for errors."] [severity "NOTICE"] [tag "no_ar"]  
[hostname "MY_HOST"] [uri "/MY_SITE/cms/pages/upload.php"]

You're getting a mod security error, which makes me suspect your server is limiting the size of uploads.

The default limit is 512kb , which could easily be much less than a modern image file.

You can increase it to a higher limit, for example 1gb by using:

SecResponseBodyLimit 1048576

You'll then need to restart the server to get it to pick up the changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM