1

I need to create process for making images into different dimensions and move them into repective folder.The below code is working for some images and not for some.Some images are being renamed in subfolder and some are not.some images are being created and some are not.I have performed unit testing on single image and it works.But when i run this on server,i get above problem.There are more than 500 images which needs to be processed.I am not able to understand where i went wrong.Please help.

    $arr=Array();
    $arr["popup"]=Array("width"=>228,"height"=>304);
    $arr["zoom"]=Array("width"=>1500,"height"=>2000);
    $source = imagecreatefromjpeg($file_path);      
    list($width, $height) = getimagesize($file_path);

    foreach($arr as $image_type=>$dimention){   
        echo "<br> $image_type : ";
        $temp_folder_name=$image_type;
                    $temp_folder_path='../prod_images/'.$folder_name.'/'.$temp_folder_name;

        //check if directory exists if not then create else traverse
        if (!file_exists($temp_folder_path)):
            mkdir($temp_folder_path);
        else:
            $files = glob($temp_folder_path.'/'.$filename);
            if (!empty($files))){
                echo "<br/>Images exists";
                $curr_dt = date('Ymd_His');
                $dt = '_'.$curr_dt;
                $file_arr = explode(".",$filename);
                $new_filename = $file_arr[0].$dt.'.'.$file_arr[1];

                $oldname = '../prod_images/'.$folder_name.'/'.$temp_folder_name.'/'.$filename;
                echo "<br>Old Name : ".$oldname;
                $newname = '../prod_images/'.$folder_name.'/'.$temp_folder_name.'/'.$new_filename;
                echo "<br>New Name : ".$newname;
                rename($oldname,$newname);
            }else{
                echo "<br/>Images does not exist";

            }
        endif;

        $curr_width=$dimention["width"];
        $curr_height=$dimention["height"];
        echo "<br> $image_type - $curr_width - $curr_height";
        $temp_image = imagecreatetruecolor($curr_width, $curr_height);
        //imagecopyresized($temp_image,$source, 0, 0, 0, 0, $curr_width, $curr_height, $width, $height);
        imagecopyresampled($temp_image,$source, 0, 0, 0, 0,$curr_width, $curr_height, $width, $height);         
        imagejpeg($temp_image,$temp_folder_path."/".$filename); 
        imagedestroy($temp_image);
piya
  • 205
  • 1
  • 6
  • 15

1 Answers1

0

According to me, your code seems ok. You might need to check the rights you get on your files and folder. Simply type ls -l on one of your folder OR, I don't recommend you to sudo chmod 777 -R ./ but I think it is the best way to check if your server has the right to write and read into your /prod_images/ folder.