| Home > Computer & I'net > PHP File Manager... |
PHP File Manager | |||||||||||||||||||||||||||||||
This article comes with a zip folder containing source code and supplimentary information. Download supplimentary files (7.03KB) BackgroundWe can find many articles related to file upload, view, download etc… This article is written on this basic concept on uploading and managing files. File upload is a process of copying the file from your machine to the remote server. Other users of the system then share this file by viewing / downloading. What happens when I upload a file, that is already exists in the remote folder to which you are uploading? While discussing this problem, various other issues arises, such as:
This article gives you a solution for all the above problems and also I hope this article will be useful for u to integrate in your projects. This article is developed with the following versions of APACHE, PHP and MYSQL Apache - 1.3.23 Operating System: Windows Professional I welcome your comments to improve the efficiency of the code. PrerequisitesTo understand this article, you should have a fair knowledge of PHP. To run examples given in your machine, you need APACHE, PHP, and MYSQL software installed and configured. Program PlanI drafted a plan on what is needed for this file version management program. Below are some features planned:
The file manager program is designed to upload and manage files. The files are stored in a predefined folder. There are two files: file_upload_manager.php and file_display_manager.php which performs the file operations. The former handles the file uploading and the later displays the file in the folder and also lets the user to delete the file. The source code is tested on Windows systems. Linux users, please change the folder path accordingly. Database Design:Database name: upload
File Upload Manager:
This program displays a menu to select the file in your system, a check box and Upload button. Once when the user clicks the upload button, the program checks the file for existence, and undergoes series of tests as described in the plan. Now lets look upon the code snippets used in the program. $dir_path VariableThis variable is the destination folder path. $dir_path= "C:\\apache\\htdocs\\filemanager\\";
This path is given for a Windows based system. Please change your destination folder accordingly. Get_New_File_Name() FunctionThis function is called from the main program when the program encounters file exists and difference in size, date or time. This function will generate a new file name and return to the main function.
The sql query in the beginning of the function will fetch file names of previous versions. If the sql query returns record sets, it means the file has previous
versions. The while loop is executed to store version number generated,
and the value obtained is stored in Next if statement checks for The return statement will return a new file name generated to the called statement. File_Size() FunctionThis function returns the file size in terms of Bytes, Kb or Mb.
Display_form() Function
This function is used to prompt the user to select the file from your local machine.
<?The Main Program
When you execute file_upload_manager.php, the following code is executed first and other function described above are called in the middle of the program. Once the user selects the file and clicks upload, 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 else 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, time stamp differs, 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. Else the user is redirected to file_display_manager.php page and a message “A previous version of this file exists” is displayed. File Display ManagerThis php program handles 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 file. dir_display() Function:This function displays the files available in the folder in a table. The template looks like this File Manager
You can see the file names are repeated. But you can see the file size and modified differs. To view / download the file, you can click the hyperlink of the file name. This will show you the file name of different version. You can customize the program to include another field “Version” to track the file version. To delete a file, click on ‘Delete’ hyperlink, this will prompts you for confirmation. ConclusionHope this technique would be useful to integrate in your projects. I welcome your comments and suggestions. Happy Programming :-) This article comes with a zip folder containing the two PHP files and the text to create the database. Download supplimentary files (7.03KB) ----------------- Murali has 2 years experience in IT and 1 year with PHP. His interests include designing, programming and learning new technologies. He is presently working for a private organization in Chennai, India. | |||||||||||||||||||||||||||||||
| Articles |
•Auto & Trucks•Business•Computer & I'net·General·Apache·CSS·Database·Hardware·HTML·Javascript&DHTML·Linux·MySQL·Operating System·Perl / CGIPHP·Programming·Publishing·Search Engines·Software Problems·SSI·Tips & Tricks·Utilities·Web Design•Family•Food & Drink•Gardening•Health•Other•Pets•Psychology•Spiritual•Travel•Women |
| Calculators |
|