我创建了一个上传脚本,它也创建了一个工作正常的缩略图,但我现在遇到了一个问题.当我上传一些图像时,exif方向数据会自动旋转我网站上的图像.
我已经尝试在线搜索如何检查数据并将其旋转回去,如果有,但我无法理解我的意图.
到目前为止,这是我的代码:
if(isset($_POST['submit'])) {
$allowedExts = array("jpg", "jpeg", "gif", "png", "JPG", "GIF");
$extension = end(explode(".", strtolower($_FILES["file"]["name"])));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
$random_numer = rand(10000000, 99999999);
$newname1 = $random_numer . $_FILES["file"]["name"];
$scramble = md5($newname1);
$extension = end(explode(".", $_FILES["file"]["name"]));
$final_name = $scramble . "." . $extension;
move_uploaded_file($_FILES["file"]["tmp_name"], "../img/gallery/" . $final_name);
create_thumbnail($final_name);
$stmt = $conn->prepare('INSERT INTO gallery (image) VALUES (:image)');
$stmt->bindParam(':image', $final_name);
$stmt->execute();
if ($stmt->rowCount() > 0) {
echo "<p class='success'>The Image has been added!
<a href='gallery.php'>Please click here to refresh</a></p>";
} else {
echo "<p class='error'>The Image was not added, there was an error.</p>";
}
}
} else {
echo "Invalid file";
}
}
如何使图像不旋转?
解决方法:
你将不得不编写另一个自定义函数,因为没有办法告诉move_uploaded_file忽略EXIF数据,这有点令人失望.