2

html表单

<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" /><p /><input type="submit" value="Uplaod" />
</form>

php函数

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;
}

上传.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

谢谢你,

4

2 回答 2

1

您可以在创建调整大小和拇指文件后立即删除上传的文件

unlink($imgDir .'/'. $img);

紧接着

$thumb  = createThumbIMK($img, $imgDir, $thumbDir, "thumb-", 150, 150);
于 2010-12-20T08:50:13.413 回答
0

取消原始链接

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);
}
于 2010-12-20T08:51:30.663 回答