我怎样才能在PHP中回显图像大小?

时间:2018-06-12 06:13:36

标签: php

我尝试将图像大小放在图像src标记中,但它仍然不起作用。图像可以很好地显示。

<?php
$files = glob("uploads/*.*");

echo "<table border =\"1\" style='border-collapse: collapse'>";

for ($row=1; $row <= 4; $row++) { 
    echo "<tr> \n";
    for ($col=1; $col<=4; $col++) { 

       $f=$f+1;
       $getfile = $files[$f]; 
       echo "<td>";
       echo "<img src=$getfile  > ";
       echo "</td>";
        }
    echo "</tr>";
    }
    echo "</table>";

2 个答案:

答案 0 :(得分:1)

您可以使用getimagesize()函数http://php.net/manual/en/function.getimagesize.php来获取图片大小

<?php 
    $files = glob("uploads/*.*");
    echo "<table border =\"1\" style='border-collapse: collapse'>";

    for ($row=1; $row <= 4; $row++) {
        echo "<tr> \n";
        for ($col=1; $col<=4; $col++) {

            $f=$f+1;
            $getfile = $files[$f];
            $size = getimagesize($getfile);
            echo "<td>";
            echo "<img src=$getfile  $size[3]> ";
            echo "</td>";
        }
        echo "</tr>";
    }
    echo "</table>";
    ?>

答案 1 :(得分:0)

PHP函数filesize将在此处解答

echo  filesize($filename) . ' bytes';

http://php.net/manual/en/function.filesize.php