为什么imagejpeg没有创建缩略图?

时间:2014-08-21 19:55:24

标签: php html5 file-upload

我上传图片的小表格及其背后的PHP脚本:

<?php
$ds          = DIRECTORY_SEPARATOR;
$storeFolder = '../../../images/gallery/pictures';
$allowedExtensions = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');

if (!empty($_FILES)) {

    if (in_array($_FILES['file']['type'], $allowedExtensions)) {

        $tempFile = $_FILES['file']['tmp_name']; 
        $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
        $targetFile =  $targetPath. $_FILES['file']['name']; 

        if (move_uploaded_file($tempFile, $targetFile)) {

            $image = imagescreatefromjpeg($storeFolder. $ds .$_FILES['file']['name']);
            $width  = imagesx($image); 
            $height = imagesy($image);

            $thumbWidth = $width * 0.3;
            $thumbHeight = $height * 0.3;
            $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
            imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumbWidth , $thumbHeight, $width, $height);
            imagejpeg($thumb, '../../../images/gallery/_thumbs/' .$_FILES['file']['name'], 80);
            imagedestroy($image);
            imagedestroy($thumb);
        }
    } 
}
?>

脚本上传文件,但当它进入最后一个if的正文时,它不会创建缩略图。

此代码有什么问题,我该如何解决?

0 个答案:

没有答案