PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Check image size before upload?

  1. charlie77
    Member

    Hi there,

    I'm using GF to create a form in which registered users can submit a post with some custom fields and an image. It works ok, but I'm finding some problems with the image upload. Whenever I try to upload an image that is bigger than aprox. 300kb, I get an Out of Memory fatal error:

    Fatal error: Out of memory (allocated 34078720) (tried to allocate 7600 bytes) in /homepages/6/d284179443/htdocs/wp-admin/includes/image.php on line 162

    I'm guessing the problem comes from having a shared hosting with 1&1, as I don't have this issue in a local server, and might consider upgrading to a dedicated server. However, with images smalles than 300 kb. would be enough for my requirements, so I'm wondering if anyone knows how could I check that the size of the image is not bigger than 300kb before the error triggers.

    I've tried plugins that resize the image, but it seems they resize it after the image is uploaded, as I still get the same error.

    Any ideas as to how could I go about this?

    Many thanks.

    Posted 10 years ago on Wednesday May 26, 2010 | Permalink
  2. Look into seeing if 1&1 can increase any of your PHP memory settings. It could be a max upload size issue or a PHP timeout issue. I'm not aware of anyway to check the file size with how it is implemented, the php upload doesn't know the file size until after it is done. We'd have to use something like a flash based uploader in order to get more info on the file. We do plan on implementing a flash uploader in the future (to allow multi-file uploads), however that doesn't help you right now. Maybe someone else may have some ideas, but i'm not aware of anyway to check the size before hand that could be integrated using a hook.

    Posted 10 years ago on Wednesday May 26, 2010 | Permalink
  3. charlie77
    Member

    Thanks Carl,

    I tried modifying memory_limit and upload_max_filesize in php.ini, but 1&1 seems to ignore the modifications, even though php.info would report the changes.

    The flash based uploader would be cool, I'd also like the multi-file uploads, but I guess it's still some months before you implement it.

    Hmm.. still hoping someone have an idea for a workaround for this issue, so we don't have to change servers.

    Thanks.

    Posted 10 years ago on Wednesday May 26, 2010 | Permalink
  4. I wonder why you're getting that error. I have 1&1 shared hosting as well, and just as a test I uploaded a 2.4MB image with a Gravity Form and it worked fine.

    This is line 162 of wp-admin/includes/image.php:
    $image = imagecreatefromstring( file_get_contents( $file ) );

    I could see if Gravity Forms was manipulating the images (like the WordPress media uploader does when creating thumbnails) but I can't see why this is erroring out for you here with a 300KB image. Might be something unique to your setup.

    Are you using the image in a post right away, where WordPress IS processing the file?

    Posted 10 years ago on Wednesday May 26, 2010 | Permalink
  5. Also, as Otto pointed out a while back, when using the media uploader, it's not so much the file size as it is the pixel size. Not sure if that's coming into play here:

    #7 here:
    http://wordpress.org/support/topic/164999?replies=1

    Posted 10 years ago on Wednesday May 26, 2010 | Permalink
  6. charlie77
    Member

    Hi Illinoisharley,

    Yes, I'm using the image in a post right away, manipulating it with the_post_thumbnail, and you might be right about that causing the problem, I'm gonna try to just upload the image.

    I'm aware that 1&1 shared hosting have around 40mb memory limit, but I also find strange that happening with just a 300kb upload.

    Also, even though I get the out of memory error, the image is uploaded to the gallery.

    Gonna give it a try, thanks for the idea!

    Posted 10 years ago on Wednesday May 26, 2010 | Permalink
  7. Right, my shared hosting has 40MB as well.

    Posted 10 years ago on Wednesday May 26, 2010 | Permalink
  8. One thing to keep in mind with 1and1 just like a lot of the shared hosting is their server configurations vary from server to server. We have seen things work fine on one BlueHost server and then the exact same thing not work as intended on another BlueHost server. Unfortunately whoever setup the server may not have done it the same way. So that could be an issue here. But it is most definitely some sort of server configuration issue.

    Posted 10 years ago on Wednesday May 26, 2010 | Permalink
  9. charlie77
    Member

    So just as an update, I tried uploading the image without manipulating it, and still getting the same error.

    I assume it has to be, as Carl says, 1&1 server configuration, or might have something to do my WP Setup as it's pretty image-heavy and uses some plugins that might be resource intensive. We were actually considering changing to a dedicated server, as due to traffic the server was straining and getting also a few 500 errors.

    Anyway, can't change the WP Setup, so I guess we'll have to try with a dedicated server, which will hopefully resolve the issue.

    Would be great though to have the Flash Uploader to ckeck size before upload, as I'd rather have people not uploading 8mb image direct from their digital camera.

    Thanks.

    Posted 10 years ago on Thursday May 27, 2010 | Permalink

This topic has been resolved and has been closed to new replies.