2011-08-04 51 views
1

我正在使用WebTechNick的文件上傳插件將圖像保存在我的CakePHP網站上。這部分工作完美。我正在使用我的projects_controller中的add動作循環播放上傳的文件,並嘗試創建並保存縮略圖。縮略圖創建順利,但在嘗試將圖像保存到縮略圖目錄時出現此錯誤。CakePHP保存縮略圖圖像錯誤(無法打開)

Unable to open 'files/project_images/thumbs' for writing: Is a directory 

我的文件,project_images,和拇指都chmoded爲777,所以我不明白爲什麼我收到一個「無法打開」的錯誤。我的完整代碼如下。

for($i=0; $i<=2; $i++){ 
       $path = 'files/'; 
       $imageName = $this->Project->Image->read('name', $imageStartingId); 
       $fullPath = $path . $imageName['Image']['name']; 
       list($width, $height) = getImageSize($fullPath); 
       $ratio = $width/$height; 
       $thumbnailHeight = $thumbnailWidth/$ratio; 
       //resample 
       $imageThumb = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight); 
       $image = imagecreatefromjpeg($fullPath); 
       imagecopyresampled($imageThumb, $image, 0,0,0,0, $thumbnailWidth, $thumbnailHeight, $width, $height); 
       imagejpeg($imageThumb, 'files/project_images/thumbs', 100); 
       $imageStartingId--;   
      } 

任何幫助,非常感謝。謝謝!

回答

1

您需要給imagejpeg()一個文件名,並且您只給出了路徑,如錯誤消息所示。更改爲

imagejpeg($imageThumb, 'files/project_images/thumbs/'.$imageName['Image']['name'], 100); 

或任何你想要的文件名。

+0

啊,那很愚蠢。謝謝。 – Bizarro181