我正在尝试使用上传/裁剪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...';
}
}
你们有没有看到潜在的问题?谢谢