Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:08:00+00:00 2026-05-26T00:08:00+00:00

I have a simple image upload script that uses SimpleImage.php (http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/) to resize and

  • 0

I have a simple image upload script that uses SimpleImage.php
(http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/)
to resize and save 2 copies of an uploaded image.

There isn’t a massive amount of validation, just checking that it exists and that the file extension is fine, and also an exif_imagetype(); call.

This has worked with no problems so far until I tried to upload a seemingly normal jpeg which turned out to be invisibly (and untestably?) corrupt. There was something not right about it, but I know very little about image corruption – it looked fine and opened no problem on anything, but when I tried to save a scaled copy in my script I got a white page.

The problem is definitely that specific image, I’ve tested exhastively with other images both from my local stock and from stock image sites, and only that one image breaks it.

I resized a copy using Photoshop (the predicted file size thingy gave me some wierd numbers – 45meg for top quality jpeg) and that uploaded with no issues.

So my question is, how do I test for this?

The image in question is here: http://chinawin.co.uk/broken.jpg //beware, 700k

notes: I’ve tested with similar resolutions, image sizes and names, everything else worked apart from this image.

UPDATE:
Through trial and error I’ve narrowed down where the script breaks to the line where I load the image into a var for SimpleImage. Strangely this is the second line that does so (the first being to create the large copy, this one to create a thumbnail).
Commenting it out means the rest works ok… perhaps some refactoring will avoid this problem.

2nd Update:
Here’s a snippet of code and some context from the line that fails:

//check if our image is OK
if ($image && $imageThumb) 
{
    //check if image is a jpeg
    if (exif_imagetype($_FILES[$k]['tmp_name']) == IMAGETYPE_JPEG)
    {
        list($width, $height, $type, $attr) = getimagesize($_FILES[$k]['tmp_name']);
        //echo 1;
        $image = new SimpleImage(); 
        //echo 2;               
        $image->load($_FILES[$k]['tmp_name']);      
        //echo 3;
        $imageThumb = new SimpleImage();
        //echo 4;

        //this next line topples my script, but only for that one image - why?:
        $imageThumb->load($_FILES[$k]['tmp_name']);
        //echo '5<br/><br/>-------<br/>';
        //do stuff, save & update db, etc
    }
}

Final edit:
Turns out my script was running out of memory, and with good reason – 4900×3900 image with 240 ppi turns out to be around 48 meg when loaded into memory, twice – so I was using probably > 90meg of ram, per image.

Hats off to @Pekka for spotting this.

Refactoring the script to only have the image loaded once, and then this variable used instead of it’s sibling, fixed my script. Still having (different) issues with upoading larger (2.5meg) images but this is for another question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:08:01+00:00Added an answer on May 26, 2026 at 12:08 am

    This is most likely a memory issue: Your JPG is very large (more than 4000 x 4000 pixels) and, uncompressed, will indeed eat up around 48 Megabytes of RAM.

    Activate error reporting to make sure. If it’s the reason, see e.g. here on what to do: Uploading images with PHP and hitting the script memory limit

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file (image) upload script in PHP that I use to upload
I currently have a PHP script I use to upload image files but I'm
I have a simple upload form working in PHP (works in web) and also
I have had problems with a simple php script in which I can upload
I have a simple Button control that contains an Image object as its content.
I'm trying to build the simple layout that I have got in the image
I have a simple table for reference page: id name description image In reference.php,
I have a script that performs some simple editing which works fine, the problem
I have a simple PHP script using imagecreatefromjpeg to create a thumbnail version of
I'm trying to do a simple image POST to a php script through FileMaker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.