如何在PHP中获取上传图像的宽度和高度

时间:2014-05-19 08:24:03

标签: php

目前这是我的代码:

echo "Upload: " . $_FILES["file"]["name"] . "<br>";
          echo "Type: " . $_FILES["file"]["type"] . "<br>";
          echo "Size: " . ($_FILES["file"]["size"] / 1024) . " KB<br>";
          echo "Stored in: " . $_FILES["file"]["tmp_name"] . "<br>";

  move_uploaded_file($_FILES["file"]["tmp_name"],"images/" . $_FILES["file"]["name"]);
            echo "images/" . $_FILES["file"]["name"];
            $path="images/" . $_FILES["file"]["name"];

2 个答案:

答案 0 :(得分:0)

$image_info = getimagesize($_FILES["file"]["tmp_name"]);
$image_width = $image_info[0];
$image_height = $image_info[1];

您可以参考:http://www.php.net/manual/en/function.getimagesize.php作为参考!

注意:在使用“getimagesize”之前,请检查上传的文件是否为图像,否则会出错。

答案 1 :(得分:0)

试试这个:

list($width, $height, $type, $attr) = getimagesize($path);
echo "Width is : " . $width;
echo "Height is : " . $height;