Php 上传后调整图片大小!
html表单Php 上传后调整图片大小!,php,html,upload,imagick,Php,Html,Upload,Imagick,html表单 <form action="upload.php" method="POST" enctype="multipart/form-data"> <input type="file" name="file" /><p /><input type="submit" value="Uplaod" /> </form> upload.php $imgDir ="uploads"; $resDir ="resized"; $th
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" /><p /><input type="submit" value="Uplaod" />
</form>
upload.php
$imgDir ="uploads";
$resDir ="resized";
$thumbDir="thumbs";
$img = $_FILES['file']['name'];
$tmpPath = $_FILES['file']['tmp_name'];
if (move_uploaded_file($tmpPath,"$imgDir/$img"))
{
$resize = createResizedIMK($img, $imgDir, $resDir, "resized-", 2);
$thumb = createThumbIMK($img, $imgDir, $thumbDir, "thumb-", 150, 150);
}
这将创建三个图像“原始图像、调整大小的图像和缩略图”
- /上传/$img
- /调整大小/$img
- /拇指/$img
- /调整大小/$img
- /拇指/$img
谢谢,您可以在创建大小调整后立即删除上载的文件,并使用
unlink($imgDir .'/'. $img);
紧接着
$thumb = createThumbIMK($img, $imgDir, $thumbDir, "thumb-", 150, 150);
取消与原始文件的链接
if (move_uploaded_file($tmpPath,"$imgDir/$img"))
{
$resize = createResizedIMK($img, $imgDir, $resDir, "resized-", 2);
$thumb = createThumbIMK($img, $imgDir, $thumbDir, "thumb-", 150, 150);
unlink($imgDir.'/'.$img);
}
if (move_uploaded_file($tmpPath,"$imgDir/$img"))
{
$resize = createResizedIMK($img, $imgDir, $resDir, "resized-", 2);
$thumb = createThumbIMK($img, $imgDir, $thumbDir, "thumb-", 150, 150);
unlink($imgDir.'/'.$img);
}