2

I am using the library WideImage to resize an uploaded image into two separate sizes then save the images in two separate directories. The problem is that the smaller image is not ALWAYS saving. Here is my attempt:

 if(move_uploaded_file($_FILES['image']['tmp_name'], "../images/temp/$id.jpg")){
        include '../../WideImage/WideImage.php';
        $successfull = 0;
        if($image = WideImage::load("../images/temp/$id.jpg")){
            if($large=$image->resize(500, 375)){
                $large->saveToFile("../images/large/product_$id.jpg");
                $successfull = 1;
            }
        }

        if($successfull==1){
            $successfull = 0;
            if($image_2 = WideImage::load("../images/temp/$id.jpg")){
                if($small=$image_2->resize(300, 225)){
                    $small->saveToFile("../images/small/product_$id.jpg");
                    $successfull = 1;
                }
            }


        if($successfull!=1){
            $showError='style="background:#c60000;"';
            $myError="An Error Occured Please Try Again";
        }
        else {
            unlink("../images/temp/$id.jpg");
            header("location: products.php");
            exit;
        }
    }

This is always giving me an error. My assumption is that the saving of the image is taking some time. So my question is how can I ensure that all the steps have been successfully completed?

user906357
  • 4,575
  • 7
  • 28
  • 38
  • 1
    don't just blindly assume the save call succeeded. Any decent function/method will have a return value to tell you what happened. You should be checking those return values instead of just blindly saying "it worked!" e.g. `$retval = $small->saveToFile(...);` – Marc B Feb 03 '15 at 19:13
  • I did try if($small->saveToFile()){} assuming it was returning a BOOL, I will try this thank you – user906357 Feb 03 '15 at 19:50
  • I tried this: if($done=$large->saveToFile(...)){} and now it is not saving at all – user906357 Feb 04 '15 at 00:35
  • I don't think that saveToFile() returns anything – user906357 Feb 04 '15 at 01:19

0 Answers0