Php 为什么我能';是否读取Exif数据并旋转图像?

Php 为什么我能';是否读取Exif数据并旋转图像?,php,exif,Php,Exif,我正在尝试进行上传图像旋转。但我无法从图像中读取Exif数据,我的旋转无法工作。我在互联网上找到了很多解决方案,但都没用。有人能帮我吗 这是我的代码: <?php if(isset($_POST['rotate'])) { $filename = $_FILES['image']['name']; $tmp_name = $_FILES["image"]["tmp_name"]; $location = 'image/'; echo $exif = ex

我正在尝试进行上传图像旋转。但我无法从图像中读取Exif数据,我的旋转无法工作。我在互联网上找到了很多解决方案,但都没用。有人能帮我吗

这是我的代码:

<?php

if(isset($_POST['rotate']))
{
    $filename = $_FILES['image']['name'];
    $tmp_name = $_FILES["image"]["tmp_name"];
    $location = 'image/';

    echo $exif = exif_read_data($tmp_name); // <----- Notice: Array to string conversion in C:\xampp\htdocs\test\novo\index.php on line 20

    if (!empty($exif['Orientation'])) {
        $source = imagecreatefromjpeg($tmp_name);
        switch ($exif['Orientation']) {
            case 3:
                $image = imagerotate($source, 180, 0);
                break;
            case 6:
                $image = imagerotate($source, -90, 0);
                break;
            case 8:
                $image = imagerotate($source, 90, 0);
                break;
            default:
                $image = $source;
        } 
        $rotatedImage = imagejpeg($image, $filename, 90);
        move_uploaded_file($tmp_name,$location.$rotatedImage);

        echo "Success";
    }
}
?>

<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit" name="rotate" value="rotate" />

</form>


<table>
<tr><td>UploadImage</td>
<td height="500px" width="500px" align="center">
<img src="image/<?php echo $image; ?>" width="300px" height="300px" />

</td>
<td>RotateImage</td>
<td headers="500px" width="500px" align="center"><img src="rotated/<?php echo $image; ?>" width="300px" height="300px" /></td></tr>
</table>
</html>

上传图像
“width=“300px”height=“300px”/>
轮换年龄
“width=“300px”height=“300px”/>

脚本的输出是什么?您试图回显$exif,但它是一个数组。var_dump($exif)的输出是什么?你确定你的exif数据包含方向信息吗?这是变量转储信息:数组(7){[“文件名”]=>string(11)“phpAC75.tmp”[“文件日期”]=>int(1573135650)[“文件大小”]=>int(86149)[“文件类型”]=>int(2)[“MimeType”]=>string(10)“图像/jpeg”[“SectionsFound”]=>string(0)”[“计算”=>array(4){[“html”=>string(25)“width=“960”height=“1280”“[“height”]=>int(1280)[“width”]=>int(960)[“IsColor”]=>int(1)}}正如您所看到的,没有方向exif dataSo,是否有其他方法使上传图像以正确的旋转?我不知道如何,您无法知道哪个旋转是正确的