Image Upload Server Error

Silverstripe Version: 4.1.0

Question:

I’m unable to upload image files greater than 2mb in size using an UploadField in the CMS. I receive the message “Server responded with an error”. I’m in DEV mode but this is all I get and nothing in the error log. Files under 2mb upload fine. I have “upload_max_filesize” set to 64M.

I have a SS 3.X site on the same server which doesn’t exhibit this problem.

Any ideas on how I can debug this?

Thanks in advance!

Hi @markholton11,

check the post_max_size variable in php.ini file.

Hope this help to solve your problem.

Thanks…!!

SilverStripe should honour the limits set in the php.ini file. A quick way to check things is to create a phpinfo file in the document root and load it in a browser. That will tell you what settings are active for the actual site (they can be different for every site on the server).

You can see in there if the upload size is limited, or the post size, etc. If it is, you should be able to see the full list of ini files which are being loaded for the site, and hopefully track down where it is being set.

Thanks @addwebsolution and @Tim for the prompt replies, sorry mine wasn’t so…

I have a phpinfo file for testing and it reports 64M for post_max_size and upload_max_size. max_execution_time is set to 120.

I’ve spoken with my hosting provider and their opinion is that the PHP settings shouldn’t be interfering with this. I’m running an SS 3.X site on the same server which works fine with the same images. I also have another hosting account with a different provider which exhibits the same problem, error in SS 4 but works ok with SS 3.

Within the Files area of the CMS there is a tile for the image, it is a draft with no thumbnail, and displays internal server error when clicked. I can’t see any trace of the image on the filesystem.

Any other pointers I could follow?

Merry Christmas!

Can you confirm a couple of things:

Are you able to upload the images in the ‘Files’ section?
What type of image is it?
What’s the filename?

If all else fails, could you post the code for your uploadfield, etc. in case there’s something odd there.

Thanks @Tim. Trying the Files section is a good idea. Unfortunately it still doesn’t work, although using different sized images I get different errors.

  • File 1: SAM_4884.JPG, 5.82MB, Error is “Server Responded with an error”
  • File 2: IMG_4197.jpg, 2.06MB, Error is “Allowed memory size of XXXX bytes is exhausted”

Don’t know why it’s different error messages, the full error for file 2 is:

ERROR [Alert]: Allowed memory size of 134217728 bytes exhausted (tried to allocate 34560001 bytes)
IN POST /admin/assets/api/createFile
Line 80 in /home/cluster-sites/4/l/littlemonsterspreloved.co.uk/public_html/vendor/intervention/image/src/Intervention/Image/Gd/Driver.php

Source
======
71:       */
72:      public function cloneCore($core)
73:      {
74:          $width = imagesx($core);
75:          $height = imagesy($core);
76:          $clone = imagecreatetruecolor($width, $height);
77:          imagealphablending($clone, false);
78:          imagesavealpha($clone, true);
79:          $transparency = imagecolorallocatealpha($clone, 0, 0, 0, 127);
*80:          imagefill($clone, 0, 0, $transparency);
81:          
82:          imagecopy($clone, $core, 0, 0, 0, 0, $width, $height);
83:  
84:          return $clone;
85:      }
86:  }

The code for my UploadField is:

private static $many_many = array(
  'LeftSideImages' => Image::class
);
private static $owns = [
  'LeftSideImages'
];
public function getCMSFields() {
  $fields = parent::getCMSFields();
  $fields->addFieldToTab("Root.Main", UploadField::create('LeftSideImages')); 
  return $fields;
}

I’ll do some more testing with different image sizes and file formats later. Does this give you any more clues??

Thanks.

thank you.
My problem was solved

That does help, actually. When you upload an image, the CMS tries to make a thumbnail of the image. The ‘out of memory’ message shows that the PHP process doesn’t have enough memory available to do this.

I don’t know what level of control you have over the configuration, but really you need to increase the PHP memory limit for the site. Hopefully this will make all the image issues go away.

SilverStripe 4 is a bit more memory-hungry compared to SS3, so this may be why you’re seeing it now.

Thanks @Tim, I can try increasing the memory limit - is there a recommended value? Currently it is set, I believe, to 128M.

I’ve also tested now with a number of different file sizes, types, names. It seems to be an issue only with JPG files, regardless of size, so even under 2MB. I’ve been able to upload PNG files in excess of 10MB without issues.

Thanks for all of your help on this.

It will depend a lot on your server configuration. Push it up to 256M and see if that cures things.

This error might also have to do with the actual pixelsize of the image more then the bytesize, because that is the crux in creating thumbnails.

I remember this happening with an architect client uploading hughe blueprints that compressed to nearly nothing yet crashed the server at thumbnail creation…

1 Like

This did the trick. My client was trying to upload 8000x6000 px images and it failed with a 500 error. I reduced the size to ~2500px in width and it worked, good catch !

This is a quite common issue: in uservoice I suggested the feature to “sanitize” the images before storing them.

As a side note, using the imagick driver should be more robust.

Sorry for the very delayed reply once again!

Thanks DorsetDigital, I’ve marked your reply as the solution as the issue seems to have gone away for my client, so it does the job. Thanks for your help.

Thanks for the insights @martimiz and @ntd, I’m sure the underlying cause is still there and may become an issue again, so I’ll keep an eye out for more permanent fixes.

Thanks all!