私はPHPの初心者のようなもので、これが私がやろうとしていることです:
- アップロードされた画像を受け取り、temp/ フォルダーに移動します
- それを調べて、サイズを変更する必要があるかどうかを判断します (幅が 135px でない場合は必要です)。
- サイズを変更する必要がある場合は、サイズを変更して結果として保存します/{number}_cover.jpg
- そうでない場合は、サイズを変更せずに、アップロードされた画像をすぐに同じ場所にコピーします
そして、ここに私のコードがあります:
$target_path = "temp/";
$target_path = $target_path . basename($_FILES["file" . $a]["name"]);
move_uploaded_file($_FILES["file" . $a]["tmp_name"], $target_path);
list($current_width, $current_height, $type, $attr) = getimagesize($target_path);
if($current_width != 135) {
$filename = $a . "_cover.jpg";
$result_image = "results/" . $filename;
$writing = fopen($result_image, 'w');
$scale = (135 / $current_width);
$new_width = 135;
$new_height = $current_height * $scale;
$result_image = imagecreatetruecolor($new_width, $new_height);
$current_image = imagecreatefromjpeg($target_path);
imagecopyresampled($result_image, $current_image, 0, 0, 0, 0, $new_width, $new_height, $current_width, $current_height);
imagejpeg($result_image, null, 100);
fclose($writing);
} else {
$target_path = "results/";
$target_path = $target_path . $a . "_cover.jpg";
move_uploaded_file($_FILES["file" . $a]["tmp_name"], $target_path);
}
ただし、これはこのコードが私のために行うことです: 1. 画像のサイズを変更する必要がある場合、ファイルに保存する代わりに、画像データをブラウザーに渡すだけです 2. サイズを変更する必要がない場合は、何も起こりません。
私は何を間違っていますか?
よろしくお願いします。