0

需要获取上传文件的尺寸,例如宽度、高度、大小等。我尝试使用getimagesize() ,但这不起作用。我得到一个错误,

Warning: getimagesize(C:/wamp/www/KSHRC/uploads/): failed to open stream: No such file or directory in C:\wamp\www\KSHRC\registration\multi_fileupload.php on line 31  

Notice: Array to string conversion in C:\wamp\www\KSHRC\registration\multi_fileupload.php on line 31  

这是代码,

for($i=0; $i < count($_FILES['userfile']['tmp_name']);$i++)
{
    $root = $_SERVER['DOCUMENT_ROOT']."/KSHRC/uploads/";    
    $filename = $_FILES['userfile']['name'][$i];
    echo $size = getimagesize($root.$filename);
}

请帮我..

4

1 回答 1

1

您必须先将文件从 tmp 移动到您想要的文件夹,然后您才能使用您的函数获取图像大小getimagesize

for($i=0; $i < count($_FILES['userfile']['tmp_name']);$i++)
{
    $root = $_SERVER['DOCUMENT_ROOT']."/KSHRC/uploads/";    
    $filename = $_FILES['userfile']['name'][$i];

    move_uploaded_file($_FILES['userfile']['tmp_name'], $root.$filename);
    echo $size = getimagesize($root.$filename);
}

更新

您还可以通过$_FILES['userfile']['size']Like this获取文件大小

$size = $_FILES['userfile']['size'];

这将返回以字节为单位的大小

更新 2

$ARR_FILES = $_FILES['userfile'];

 for($i=0; $i < count($ARR_FILES);$i++)
    {
        $root = $_SERVER['DOCUMENT_ROOT']."/KSHRC/uploads/";    
        $filename = $ARR_FILES[$i]['name'];
        $tmp_name = $ARR_FILES[$i]['tmp_name'];
        list($width, $height, $type, $attr) = getimagesize($tmp_name); 
       echo $width;
       echo $height;
    }
于 2014-02-14T08:31:25.650 回答