recently got fed up with using the usual shared-directories mechanism to implement file sharing. Not only are there too many permissions to define at the administrator level, it also requires all the actions for sharing files among different operating systems. And what if you have just an Internet connection? Sure you can use email or FTP, but those aren't exactly elegant solutions.
I finally made up my mind to use PHP instead. I wrote a PHP file-sharing program that did all this:
- Uploads and downloads files with a browser
- Stores these files with metadata on a relational database management system (RDBMS)
- Encrypts and compresses files when possible
- Organizes the files, avoiding a hierarchical approach (directories) and preferably tagging them with labels and grouping them in a very different way
When I had the basic program completed, I wanted to upgrade it using these optimization guidelines:
- Write fewer lines of code.
- Use a popular RDBMS.
- Separate the HTML code and, if possible, delegate it to someone who is more expert than I am.
This article presents my optimized PHP program as a practical example for file sharing on Internet. It demonstrates how to integrate open source libraries and frameworks, use a database abstraction layer, and decouple application logic from the presentation. While not the most elegant implementation of the MVC (Model Control View) paradigm, it does show how the integration of different open source helper packages works and how these can make your life easier.