Skip to content

Instantly share code, notes, and snippets.

@pj8912
Created March 16, 2021 05:29
Show Gist options
  • Save pj8912/fb2c8d6c7388430cf0f47a59877af20a to your computer and use it in GitHub Desktop.
Save pj8912/fb2c8d6c7388430cf0f47a59877af20a to your computer and use it in GitHub Desktop.
php get file information
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Info</title>
</head>
<body>
<form action="" enctype="multipart/form-data" method="post">
<input type="file" name="file" accept="*">
<button type="submit" name="sbtn">submit</button>
</form>
<hr>
<?php
if (isset($_POST['sbtn'])) {
// gives full information of the file
$fileInfo = $_FILES['file'];
print_r($fileInfo);
echo '<hr>';
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
// in case of uploading file
$tmp_name = $_FILES['file']['tmp_name'];
echo "details:<br>";
$size_in_mb = number_format($size/1048576, 2);
echo ' <table>
<thead>File Info</thead>
<tr>
<td>Name:</td>
<td>'.$name.'</td>
</tr>
<tr>
<td>Type:</td>
<td>'.$type.'</td>
</tr>
<tr>
<td>Size(in bytes):</td>
<td>'.$size.'</td>
</tr>
<tr>
<td>Size(in MB):</td>
<td>'.$size_in_mb.'MB</td>
</tr>
</table>';
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment