Today,I’m trying to display the name, size and type of a file uploaded. Mainly here I explains how to get the file name, file size (in bytes), file type (Image/Text/PDF/spreadsheet files) after select the documents.
Uploading the files in php page using ‘file’ type in HTML input like <input type=”file” name=”image”/>. Some times we may need to know the file name,type and size of the file that is uploaded.
Here is give a simple method to get the file name, type and size of the file that is being uploaded in pure php page.
Basically when the user selects any files using input file tag we will display its file name, file size and file type of files selected.
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="image" required/ />
$file_name = $_FILES['image']['name'];
echo "File Name:$file_name<br/> File Size : $file_size <br/> File Type :$file_type ";
//echo '<script>alert(" File Name:'.$file_name.' File Size : '.$file_size .' File Type : '.$file_type .'")</script>';
Description: Here we first add a input file tag and button within form tag. If we select the files then it display name,size and type of file selected. Using Html5 we can also preview image preview image