PHP 获取图像高度和宽度

发布于 2024-12-06 22:05:47 字数 1193 浏览 1 评论 0原文

您好,我需要动态获取上传图像的高度和宽度。

这是我正在使用的 PHP 函数,但它不会返回任何宽度和高度。

您能帮我吗?

list($width, $height, $type, $attr) = getimagesize($_FILES["Artwork"]);
$min_width = "1000";
$min_height = "1000";
if ((($_FILES["Artwork"]["type"] == "image/gif") || ($_FILES["Artwork"]["type"] == "image/jpeg") || ($_FILES["Artwork"]["type"] == "image/jpg")
|| ($_FILES["Artwork"]["type"] == "image/pjpeg")) && ($_FILES["Artwork"]["size"] < 20000000) && ($width > $min_width) && ($height > $min_height) && ($width == $height))
  {


  if ($_FILES["Artwork"]["error"] > 0)
    {
    //echo "Return Code: " . $_FILES["Artwork"]["error"] . "<br />";


   }else{
      move_uploaded_file($_FILES["Artwork"]["tmp_name"],
      $path_image . $imageName);
      header("Location: http://pitchmystuff.co.uk/m/digidist/tracks/".$idAlbum."");
      }



   }else{
    //echo "invalid file";

    echo '<script>
    alert("There was an error uploading your coverart file. Please check the requirements and try again.'.$width.$height.'");
    document.location ="http://pitchmystuff.co.uk/m/digidist/albums/";
    </script>';


    }

Hello I need to get the height and width on the fly of an uploaded image.

This is the PHP function I am using, but it does not return anything for the width and height..

Could you please help me?

list($width, $height, $type, $attr) = getimagesize($_FILES["Artwork"]);
$min_width = "1000";
$min_height = "1000";
if ((($_FILES["Artwork"]["type"] == "image/gif") || ($_FILES["Artwork"]["type"] == "image/jpeg") || ($_FILES["Artwork"]["type"] == "image/jpg")
|| ($_FILES["Artwork"]["type"] == "image/pjpeg")) && ($_FILES["Artwork"]["size"] < 20000000) && ($width > $min_width) && ($height > $min_height) && ($width == $height))
  {


  if ($_FILES["Artwork"]["error"] > 0)
    {
    //echo "Return Code: " . $_FILES["Artwork"]["error"] . "<br />";


   }else{
      move_uploaded_file($_FILES["Artwork"]["tmp_name"],
      $path_image . $imageName);
      header("Location: http://pitchmystuff.co.uk/m/digidist/tracks/".$idAlbum."");
      }



   }else{
    //echo "invalid file";

    echo '<script>
    alert("There was an error uploading your coverart file. Please check the requirements and try again.'.$width.$height.'");
    document.location ="http://pitchmystuff.co.uk/m/digidist/albums/";
    </script>';


    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ペ泪落弦音 2024-12-13 22:05:47

应该

list($width, $height, $type, $attr) = getimagesize($_FILES["Artwork"]['tmp_name']);

参见 http://www.php.net/手册/en/features.file-upload.post-method.php

Should be

list($width, $height, $type, $attr) = getimagesize($_FILES["Artwork"]['tmp_name']);

See http://www.php.net/manual/en/features.file-upload.post-method.php

少跟Wǒ拽 2024-12-13 22:05:47
<?php

$imagedetails = getimagesize($_FILES['Artwork']['tmp_name']);
$width = $imagedetails[0];
$height = $imagedetails[1];

?>
<?php

$imagedetails = getimagesize($_FILES['Artwork']['tmp_name']);
$width = $imagedetails[0];
$height = $imagedetails[1];

?>
爱情眠于流年 2024-12-13 22:05:47
<?php
/*$size = getimagesize("http://heartbeatperformance.com.p9.hostingprod.com/customerphotos/photoes/51HDE3cnl2L.jpg");

list($width, $height) = $size;
echo "width: $width<br />height: $height";*/



$testing = "http://heartbeatperformance.com.p9.hostingprod.com/customerphotos/img/logo.png";
//echo $testing;
list($width, $height, $type, $attr) = getimagesize($testing);
echo "Image width " . $width;
echo "Image height " . $height;



?>
<?php
/*$size = getimagesize("http://heartbeatperformance.com.p9.hostingprod.com/customerphotos/photoes/51HDE3cnl2L.jpg");

list($width, $height) = $size;
echo "width: $width<br />height: $height";*/



$testing = "http://heartbeatperformance.com.p9.hostingprod.com/customerphotos/img/logo.png";
//echo $testing;
list($width, $height, $type, $attr) = getimagesize($testing);
echo "Image width " . $width;
echo "Image height " . $height;



?>
百变从容 2024-12-13 22:05:47
$DOCS_NAME = $_FILES['DOCS']['name'];
$DOCS_SIZE = getimagesize($_FILES['DOCS']['tmp_name']);
$DOCS      = file_get_contents ($_FILES['DOCS']['tmp_name']);
$FILE_SIZE = $_FILES["DOCS"]["size"];
$FILE_TYPE = $_FILES["DOCS"]["type"];

echo 'Width     = '.$DOCS_SIZE[0]. "<br />";
echo 'Height    = '.$DOCS_SIZE[1]. "<br />";;  
echo '2         = '.$DOCS_SIZE[2]. "<br />";;  
echo '3         = '.$DOCS_SIZE[3]. "<br />";;  
echo 'bits      = '.$DOCS_SIZE['bits']. "<br />";;
echo 'channels  = '.$DOCS_SIZE['channels']. "<br />";;
echo 'mime      = '.$DOCS_SIZE['mime']. "<br />";
echo 'type      = '.$_FILES["DOCS"]["type"]. "<br />";
echo 'size      = '.$_FILES["DOCS"]["size"]. "<br />"; 
$DOCS_NAME = $_FILES['DOCS']['name'];
$DOCS_SIZE = getimagesize($_FILES['DOCS']['tmp_name']);
$DOCS      = file_get_contents ($_FILES['DOCS']['tmp_name']);
$FILE_SIZE = $_FILES["DOCS"]["size"];
$FILE_TYPE = $_FILES["DOCS"]["type"];

echo 'Width     = '.$DOCS_SIZE[0]. "<br />";
echo 'Height    = '.$DOCS_SIZE[1]. "<br />";;  
echo '2         = '.$DOCS_SIZE[2]. "<br />";;  
echo '3         = '.$DOCS_SIZE[3]. "<br />";;  
echo 'bits      = '.$DOCS_SIZE['bits']. "<br />";;
echo 'channels  = '.$DOCS_SIZE['channels']. "<br />";;
echo 'mime      = '.$DOCS_SIZE['mime']. "<br />";
echo 'type      = '.$_FILES["DOCS"]["type"]. "<br />";
echo 'size      = '.$_FILES["DOCS"]["size"]. "<br />"; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文