2012-03-28 46 views
0

我需要在成功上傳圖片文件後製作圖片的縮略圖。我寫了這個函數,但它似乎不起作用。希望任何人都能幫忙。由於無法使用php製作上傳圖片的縮略圖

function make_thumb($src, $thumbDest, $thumbWidth){ 
    $sourceImage = imagecreatefromjpeg($src); 
    $theWidth  = imagesx($sourceImage); 
    $theHeight = imagesy($sourceImage); 

    $thumbHeight = floor($theHeight * ($thumbWidth/$theWidth)); 
    $tempImage = imagecreatetruecolor($thumbWidth, $thumbHeight); 
    imagecopyresized($tempImage, $sourceImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $theWidth, $theHeight); 

    imagejpeg($tempImage, $thumbDest); 
    imagedestroy($tempImage); 
    imagedestroy($sourceImage); 
} 
+0

定義「不起作用」請 – haltabush 2012-03-28 20:25:30

+0

它不會將所創建的縮略圖保存到給定的目標文件夾中,並且不顯示任何內容。 – Thavarith 2012-03-28 20:46:42

+0

您是否啓用了error_reporting指令?同時檢查你的錯誤日誌。 – haltabush 2012-03-28 20:52:25

回答

1

如果你是在Linux上,檢查/ var /日誌/的httpd/error_log中或/ var /日誌/的Apache2/error_log中看到它之所以失敗(如果你有錯誤報告關閉。)

此外,它可能是由於文件權限問題。確保$ thumbDest目標文件夾/目錄可由Apache或Web服務器運行的用戶寫入。

+0

是的,非常感謝。它已經工作。 – Thavarith 2012-03-28 21:06:11