ユーザー アップロード フォームから画像のサイズを変更し、$_FILES
配列の内容をサイズ変更関数に渡しました。この関数は、GD を使用して画像のサイズを変更し、目的のディレクトリに保存します。
画像のコピーを 2 つ作成する必要があります。1 つは大きなコピー、もう 1 つはサムネイル用の小さなコピーです。サムネイル画像を作成するために関数を 2 度目に (ただし次元が異なる) 呼び出そうとすると、問題が発生します。配列のunidentified index
配列メッセージが表示されます$_FILES
。
$_FILES
関数を使用してクリアしていないにもかかわらず、関数に渡した後、配列は自動的に削除されますか?
FUNCION CALLは次のとおりです
if ($_FILES['image']['error'] != 4){
foto($_FILES['image'], $THUMBS_DIR, 400, 400, 1);
foto($_FILES['image'], $THUMBS_DIR, 70, 70, 1);
}
関数
/*foto function, foto upload, where to save, fotowidth, fotosize,*/
function foto($_FILES, $THUMBS_DIR, $MAX_WIDTH, $MAX_HEIGHT){
/*generate random name*/
$fecha = time();$passpart1 = $fecha;$passpart2 = mt_rand(1, 1000);$ps = $passpart1.$passpart2;$ps2= $passpart1.$passpart2.'thumb';$thumbref='0';
if (is_uploaded_file($_FILES['tmp_name']))
{
/*resize ratio*/
$original = $_FILES['tmp_name'];
list($width, $height, $type) = getimagesize($original);
if ($width <= $MAX_WIDTH && $height <= $MAX_HEIGHT) {$ratio = 1;}
elseif ($width > $height) {$ratio = $MAX_WIDTH/$width;}
else {$ratio = $MAX_HEIGHT/$height;}
$imagetypes = array('/\.gif$/','/\.jpg$/','/\.jpeg$/','/\.png$/');
$name = preg_replace($imagetypes, '', basename($original));
$name=$ps;switch($type)
{case 1:$source = @ imagecreatefromgif($original);if (!$source) {$result = 'Cannot process GIF files. Please use JPEG or PNG.';}break;
case 2:$source = imagecreatefromjpeg($original);break;
case 3:$source = imagecreatefrompng($original);break;
default:$source = NULL;$result = 'Cannot identify file type.';}
if (!$source) {$result = 'Problem copying original';}
else {
$thumb_width = round($width * $ratio);
$thumb_height = round($height * $ratio);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
switch($type)
{case 1:if (function_exists('imagegif')) {$success = imagegif($thumb, $THUMBS_DIR.$ps.'.gif');$thumb_name = $ps.'.gif';}
else {$success = imagejpeg($thumb, $THUMBS_DIR.$ps.'.jpg', 50);$thumb_name = $ps.'.jpg';}break;
case 2:$success = imagejpeg($thumb, $THUMBS_DIR.$ps.'.jpg', 100);$thumb_name = $ps.'.jpg';break;
case 3:$success = imagepng($thumb, $THUMBS_DIR.$ps.'.png');$thumb_name = $ps.'.png';}
/*destroy temp or not*/
if ($success) {$result = "$thumb_name created";}
}
$fotref = $thumb_name;
}
else{$errorreport='error with upload';}}
こんにちは、コードを投稿しました。最初は投稿していませんでした。なぜなら、人々が見たいと思っていなかったからです。本当に感謝しています。皆さんに感謝します。