我有一个相当简单的脚本来处理从 Uploadify 发送到服务器的文件信息,除了创建缩略图之外一切正常。谁能看到我的错误在哪里?
<?php
session_start();
include "../_db.inc";
/*
Uploadify v3.1.0
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
// Define a destination
$targetFolder = '/images/artist_pictures/'; // Relative to the root
$thumbsFolder = '/images/artist_pictures/thumbs/'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$yourid = (int)$_POST['yourid'];
$extension = end(explode(".", $_FILES['Filedata']['name']));
$filename = "artist_".$yourid.".".$extension;
$targetFile = rtrim($targetPath,'/') . '/' . $filename;
$targetThumb = rtrim($thumbsFolder,'/') . '/' . $filename;
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png','JPG','bmp'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
// CREATE THUMBNAIL
if($extension=="jpg" || $extension=="jpeg") {
$src = imagecreatefromjpeg($tempFile);
}
else if($extension=="png") {
$src = imagecreatefrompng($tempFile);
}
else {
$src = imagecreatefromgif($tempFile);
}
list($width,$height)=getimagesize($tempFile);
$newwidth=50;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$thumbname = $targetThumb;
if (file_exists($thumbname)) {
unlink($thumbname);
}
imagejpeg($tmp,$thumbname,100);
imagedestroy($src);
imagedestroy($tmp);
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
?>
提前致谢!科林