html formu
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" /><p /><input type="submit" value="Uplaod" />
</form>
php function
function createResizedIMK($img, $imgPath, $thumbDir, $suffix, $by) {
// add in the suffix after the '.' dot.
$newNameE = explode(".", $img);
$newName = ''. $newNameE[0] .''. $suffix .'.'. $newNameE[1] .'';
// ImageMagicK doesnt like '/' and 'x' characters in the command line call.
// And workout the size based on '$by'.
$uploadedImg = ''. $imgPath .'/'. $img .'';
$newResized = ''. $reduceDir .'/'. $newName .'';
list($width, $height, $type, $attr) = getimagesize("$imgPath/$img");
$newWidth = ($width/$by);
$newHeight = ($height/$by);
$newRes = ''. $newWidth .'x'. $newHeight .'';
// This makes a command line call to ImageMagicK.
// My path to ImageMagicK Convert is '/usr/lib/php/bin/convert'
// 'convert' is a program (UNIX) so no forward slash.
$cr = system("/usr/lib/php/bin/convert -resize $newRes $uploadedImg $newResized", $retval);
return $cr;
}
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);
}
Bu üç görüntüleri "orijinal, diğeri minik resized" yaratacak,
- / Yüklenenler $ / img
- / Resized / $ img
- / Thumbs / $ img
Nasıl bu orijinal görüntü çıkışı ile sadece iki görüntüleri (resized tek ve küçük) oluşturmak için yapabilirsiniz!
- / Resized / $ img
- / Thumbs / $ img
, teşekkür ederim