Get File Size and File Type In PHP

by Hiroshi on September 30, 2008

in File, File Manipulation, Info, Tricks

With this PHP script you can find size and type (extension) of required file.

Get File Size and Type

Create a form with single file field named as file.

<form action="getInfo.php" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="Submit" value="Submit">

Browse and put a file in it and post to other PHP page getInfo.php containing following script.

// file name
echo "Image name > $image";
echo "<br><br>";
// file size
echo "Image Size > $file_size";
echo "<br><br>";
// file size in KB
echo "Image Size > $ms KB";
echo "<br><br> or ";
echo $file . ': ' . filesize($file) . ' bytes';
// file type
echo "File Type > $file_type";

Using this you should be able to get file info.

Download File Size and Type Example
:: Example works with Globals on (not recommended, Do Globals on for learning purpose only)

Related Posts

Previous post:

Next post: