Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get uploaded file size in bytes in php

Tags:

php

I am uploading a file which is an image. I want to get the size of that image every time in bytes only using PHP. I had done this by far

$name=$_FILES['image']['name'];
if($name!=null)
{
    $tmpDest=$_FILES['image']['tmp_name'];
    $size=$_FILES['image']['size'];
    $perDestination="main/$name";
    $result=move_uploaded_file($tmpDest,$perDestination);
    echo $size;
}
like image 470
Amanjot Kaur Avatar asked Aug 21 '15 04:08

Amanjot Kaur


1 Answers

Your code is right, the below line will give you the size in bytes:

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

You can also get the file size after the file has been uploaded this way:

echo filesize($perDestination) . ' bytes';  

This option will also give you the file size in bytes

like image 64
Luthando Ntsekwa Avatar answered Nov 06 '22 01:11

Luthando Ntsekwa