2016-05-28 9 views
1

イメージを別の次元に作成し、それぞれのフォルダーに移動するプロセスを作成する必要があります。下のコードはいくつかのイメージで機能しています。一部のイメージはサブフォルダいくつかはありませんいくつかの画像が作成されていますが、一部は作成されていません。私は単体テストで単体テストを実行していますが、これはサーバー上で実行すると問題になります。どこが間違っているのか理解できません。助けてください。イメージの作成と名前の変更がPHPで機能しない

$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); 
+1

_minimal_関連するコードを入力してください。 –

+0

絶対パスを使用してください。 –

答えて

0

私によると、あなたのコードは大丈夫そうです。 ファイルとフォルダの権限を確認する必要があります。 単にls -lと入力してください。 sudo chmod 777 -R ./にはお勧めできませんが、サーバーに/ prod_images /フォルダの書き込み権と読書権があるかどうかを確認する最も良い方法だと思います。

関連する問題