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

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

これにより、「元のサイズ変更された画像とサムネイル」の3つの画像が作成されます。

  • / uploads / $ img
  • / resized / $ img
  • / thumbs / $ img

元の画像なしで2つの画像(サイズ変更された画像とサムネイル)だけを作成するには、どうすればよいですか?

  • / resized / $ img
  • / thumbs / $ 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 に答える