Home arrow PHP arrow Page 4 - File Management with PHP

The Main Program - 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?

  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



When you execute file_upload_manager.php, the code is executed first and the other functions described above are called in the middle of the program. Once the user selects the file and clicks upload, the main program part is executed. Here the program gets the upload file information like file size, file type, date modified and time stamp. Next it checks for the file existence in the destination folder. If the file is present the "if" part of the program gets executed, otherwise the file is copied to the destination folder and the file information is inserted in the database. If the file exists, and if the file size and/or time stamp differs, Get_New_File_Name() function is called to generate a new file name. Then the file is copied to the destination folder and the file information is stored in the database. If the file exists and the user had checked the "Replace Existing File" option, the file is replaced and the file information is updated in the database accordingly.

Otherwise, the user is redirected to the file_display_manager.php page and the message "A previous version of this file exists" is displayed.

File Display Manager:
This PHP script handles the displaying of files present in the folder. As described in the plan, the program will display the file name, size, type and an option to delete the file.

dir_display() Function:

This function displays the files available in the folder in a table. The template looks like this:

File Manager


abc.doc25 KbdocOct 01, 2003Delete
xyz.txt24 bytestxtOct 03, 2003Delete
abc.doc48 KbdocOct 05, 2003Delete
abc.doc67 KbdocNov 05, 2003Delete
xyz.txt58 bytestxtOct 23, 2003Delete

You can see that the file names are repeated, but you can see the file size and date modified differs. To view and/or download the file, you can click the hyperlink of the file name. This will show you the file name of the different version. You can customize the program to include another field "Version" to track the file version.

To delete a file, click on the 'Delete' hyperlink, which will prompt for confirmation.

I welcome your comments and suggestions!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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: