我有圖片上傳腳本,當我們上傳圖片或圖片時,功能調整大小,
從原始圖片製作兩張圖片,一張是205 * 256,另一張是205 * 256是800 * 500.圖像 調整大小工作正常,但問題是,當我上傳和調整圖像大小,然後 原始圖像也移動到目錄...我希望只有調整大小的圖像在我的 目錄。 ...現在的問題是,我怎麼能從目錄中刪除原始圖像...我 不想在原始圖像的目錄..原始圖像不能移動到目錄..提前感謝!如何在調整大小後刪除原始圖像
<?php
if($_POST['btnSubmit'])
{
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
{
if(trim($_FILES["fileUpload"]["tmp_name"][$i] !=""))
{
$images = $_FILES["fileUpload"]["tmp_name"][$i];
list($width, $height, $type, $attr) = getimagesize($images);
if($width>600 && $height>480)
{
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"][$i];
move_uploaded_file($_FILES["fileUpload"]["tmp_name"][$i],"$output_dir".$_FILES["fileUpload"] ["name"][$i]);
$res = resize(800,500,$_FILES["fileUpload"]["name"][$i],$_FILES["fileUpload"]["type"][$i]);
$width=205;
$height=256;
$size=GetimageSize($res);
$images_orig = ImageCreateFromJPEG($res);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageJPEG($images_fin,"$output_dir".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Resize Successful.<br>";
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("datbase");
$strSQL = "INSERT INTO gallery ";
$strSQL .="(id,filename,Thumbnails) VALUES ('','".$_FILES["fileUpload"]["name"][$i]."','".$new_images."')";
$objQuery = mysql_query($strSQL);
}
else
{
//upload the image with out changing
}
?>
//This is the resize function
<?php
$output_dir = "MyResize/";
function resize($width, $height,$image,$type){
global $output_dir;
$relPath = $output_dir.$image;
list($w, $h) = getimagesize($relPath);
/* calculate new image size with ratio */
$ratio = max($width/$w, $height/$h);
$h = ceil($height/$ratio);
$x = ($w - $width/$ratio)/2;
$w = ceil($width/$ratio);
/* new file name */
$thumb = $output_dir.$width.'x'.$height.'_'.$image;
//echo $thumb; exit;
/* read binary data from image file */
$imgString = file_get_contents($relPath);
//echo $imgString ; exit;
/* create image from string */
$image = imagecreatefromstring($imgString);
//echo $image; exit;
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $image,
0, 0,
$x, 0,
$width, $height,
$w, $h);
/* Save image */
switch ($type) {
case 'image/jpeg':
{
//echo $tmp; exit;
imagejpeg($tmp,$thumb,100);
break;
}
case 'image/jpg':
{
imagejpeg($tmp,$thumb,100);
break;
}
case 'image/png':
{
imagepng($tmp, $thumb, 0);
break;
}
case 'image/gif':
{
imagegif($tmp, $thumb);
break;
}
default:
break;
}
return $thumb;
/* cleanup memory */
imagedestroy($image);
imagedestroy($tmp);
}
?>
'的unlink刪除原始圖片($ originalImagePath);' – 2014-11-25 05:23:44
刪除了cakephp標誌,因爲這是cleary,甚至沒有遠程cakephp相關。 – mark 2014-11-25 06:09:58