PHP Magic Book – Free PHP Scripts, Tutorials and Downloads, PHP AtoZ Reloaded, free php tutorials, free php downloads, php scripts, PHP tips

Get File Size and File Type In PHP

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">
</form>

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

<?php
$file=$_REQUEST["file"];
$image=$_FILES['file']['name'];
// file name
echo "Image name > $image";
echo "<br><br>";
// file size
echo "Image Size > $file_size";
echo "<br><br>";
// file size in KB
$size="$file_size";
$ms=$size/1024;
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)

  • Share/Bookmark
Tags: , ,
Posted in: File, File Manipulation, Info, Tricks
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Related Posts




Post a Comment

  Subscribe Via RSS
  Subscribe Via Email