我正在寻找一种在上传照片之前调整照片大小的方法,我找到了下面的代码,它完全符合我的目标,只是希望它不会将原始图像与裁剪图像一起存储在目录中。我对它做了一些更改,但没有成功。我希望我能得到一些帮助。 if(isset($_POST["submit"])) { if(is_array($_FILES)) { $uploadedFile = $_FILES['file']['tmp_name']; $sourceProperties = getimagesize($uploadedFile); $newFileName = time(); $dirPath = "uploads/"; $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); $imageType = $sourceProperties[2]; switch ($imageType) { case IMAGETYPE_PNG: $imageSrc = imagecreatefrompng($uploadedFile); $tmp = imageResize($imageSrc,$sourceProperties[0],$sourceProperties[1]); imagepng($tmp,$dirPath. $newFileName. "_thump.". $ext); break; case IMAGETYPE_JPEG: $imageSrc = imagecreatefromjpeg($uploadedFile); $tmp = imageResize($imageSrc,$sourceProperties[0],$sourceProperties[1]); imagejpeg($tmp,$dirPath. $newFileName. "_thump.". $ext); break; case IMAGETYPE_GIF: $imageSrc = imagecreatefromgif($uploadedFile); $tmp = imageResize($imageSrc,$sourceProperties[0],$sourceProperties[1]); imagegif($tmp,$dirPath. $newFileName. "_thump.". $ext); break; default: echo "Invalid Image type."; exit; break; } move_uploaded_file($uploadedFile, $dirPath. $newFileName. ".". $ext); echo "Image Resize Successfully."; } } function imageResize($imageSrc,$imageWidth,$imageHeight) { $newImageWidth =900; $newImageHeight =534; $newImageLayer=imagecreatetruecolor($newImageWidth,$newImageHeight); imagecopyresampled($newImageLayer,$imageSrc,0,0,0,0,$newImageWidth,$newImageHeight,$imageWidth,$imageHeight); return $newImageLayer;}?>
1 回答
慕姐8265434
TA贡献1813条经验 获得超2个赞
如果从代码中删除该行,则不会保存原始文件(原始文件将保留在临时文件夹中并最终被系统删除)。代码的其余部分应按原样工作。move_uploaded_file
- 1 回答
- 0 关注
- 93 浏览
添加回答
举报
0/150
提交
取消