Home arrow PHP arrow Page 3 - File Management with PHP

File_Size() and Display_form Functions - PHP

We can find many articles related to uploading, viewing, and downloading files. This article is written on the basic concept of uploading and managing files. File uploading is the process of copying the file from your machine to the remote server. Other users of the same system then share this file by viewing or downloading it. What happens when you upload a file that already exists in the remote folder to which you are uploading?

TABLE OF CONTENTS:
  1. File Management with PHP
  2. Building the Database
  3. File_Size() and Display_form Functions
  4. The Main Program
By: Murali Dharan.M
Rating: starstarstarstarstar / 77
March 29, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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>
<? } ? 
>




 
 
>>> More PHP Articles          >>> More By Murali Dharan.M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: