Web サイトに必要な画像アップロード フォームにアップロード/クロップ php スクリプトを使用しようとしています。聞いたことのある人なら誰でも ImageManipulator.php を使用し、アップロードは正常に機能しますが、実際のトリム/クロップとフォルダーへの追加は機能しません。これが私のコードです:
//Avatar Preferences
$avatar = mysqli_real_escape_string($con, $_REQUEST["avatar"]);
// include ImageManipulator class
require_once('../scripts/ImageManipulator.php');
if ($_FILES[$avatar]['error'] > 0) {
echo "Error: " . $_FILES[$avatar]['error'] . "<br />";
} else {
// array of valid extensions
$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
// get extension of the uploaded file
$fileExtension = strrchr($_FILES[$avatar]['name'], ".");
// check if file Extension is on the list of allowed ones
if (in_array($fileExtension, $validExtensions)) {
$newNamePrefix = time() . '_';
$manipulator = new ImageManipulator($_FILES[$avatar]['tmp_name'])or die(mysqli_error());
$width = $manipulator->getWidth();
$height = $manipulator->getHeight();
$centreX = round($width / 2);
$centreY = round($height / 2);
// our dimensions will be 200x130
$x1 = $centreX - 100; // 200 / 2
$y1 = $centreY - 65; // 130 / 2
$x2 = $centreX + 100; // 200 / 2
$y2 = $centreY + 65; // 130 / 2
// center cropping to 200x130
$newImage = $manipulator->crop($x1, $y1, $x2, $y2);
// saving file to uploads folder
$manipulator->save('../uploads/' . $newNamePrefix . $_FILES[$avatar]['name']);
echo 'Done ...';
} else {
echo 'You must upload an image...';
}
}
ここで潜在的な問題を見つけた人はいますか?ありがとうございました