RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Secure Internet File-Sharing with PHP, MySQL, and JavaScript

Use PHP to create a secure Internet file-sharing application that employs a database abstraction layer and separates HTML design from PHP programming.

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.
  • Shorten the workflow of interactions with JavaScript pop-ups without mixing languages.

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.

What You Need
A running Apache 2.X instance with a PHP 5.X module
A RDBMS database supported by PHP (The example uses MySQL 4.X)
The Smarty package
The overLIB package
An Internet connection

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date