Reputation: 79
Need to get the dimensions of the uploaded files such as width, height, size, etc. I tried using getimagesize()
, but that does not works. I get an error,
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
and
Notice: Array to string conversion in C:\wamp\www\KSHRC\registration\multi_fileupload.php on line 31
Here's the code,
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);
}
Please help me..
Upvotes: 0
Views: 689
Reputation:
you have to move the file from tmp to your desired folder first then you can get the image size by using your function 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);
}
Update
you can also get the file size by $_FILES['userfile']['size']
Like this
$size = $_FILES['userfile']['size'];
this will return size in bytes
UPDATE 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;
}
Upvotes: 1