File Management with PHP - File_Size() and Display_form Functions (
Page 3 of 4 )
File_Size() Function:
This function returns the file size
in terms of Bytes, Kb or Mb.
<?
function
File_Size($size)
{
if($size >
104876){
return
$return_size=sprintf("%01.2f",$size / 1048576)."
Mb";
}elseif($size >
1024){
return
$return_size=sprintf("%01.2f",$size / 1024)." Kb";
}else{
return $return_size=$size."
Bytes";
}
}
? >
Display_form() Function:
This function is used to prompt
the user to select the file from your local machine.
<?
function display_form($errMsg){
global $dir_path; ? >
<html>
<head><title>File
Manager</title></head>
<body bgcolor="#E5E5E5">
<div
align="center">
<h4>File Manager</h4>
<? if($errMsg){
? ><font face="verdana, helvetica" size="2"
color="red"><? echo $errMsg ? ></font>
<?
}
?
>
<form action="<? echo $PHP_SELF; ? >"
enctype="multipart/form-data"
method="POST">
<table border="1">
<tr><th>File
Location:</th><th><input type="file" name="up_file"
/></th></tr>
<tr><th
colspan="2"><br><input type="checkbox" name="replace"
value="1">Replace Exiting File*</th></tr>
<tr><th
colspan="2"><br><input type="submit" name="upload" value="Upload
File !" /></th></tr>
</table>
<br>* - Clicking this option will replace the existing
file
<br><a href="file_display_manager.php">File
Manager</a>
<br><? if ($status){ echo "Result :".$status; }?
>
<p><br><b>Folder Location:</b><? echo $dir_path ?
>
<br>You can change this location by editing the
file</font>
</form>
</div>
</body>
</html>
<? } ?
>