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

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

Installation Instructions for a Quick Start
The server infrastructure for the example program requires a web server that can run PHP code, and the PHP interpreter has to be compiled with the support of the selected RDBMS. In my case, I chose the LAMP framework: Linux (Debian), Apache, MySQL and, obviously, PHP. The following installation instructions assume you have working installs of Apache 2.X, PHP 5.X, and MySQL 4.X, as well as an Internet connection.

To begin, download the accompanying source code for this article, and extract the file_sharing.zip file under the web server documents root (from now on [document_root]) with the following command:

unzip file_sharing.zip

PEAR MDB2 Installation
The installation of PEAR packages requires an installer that you already have available if you installed PHP version 4.3.0 or higher. If so, you just run this on the command line:

pear install MDB2
pear install MDB2#mysql

Smarty Installation
To install the Smarty template engine (more on Smarty later), run the following if you are a Debian user:

apt-get install smarty

If you use another Linux system, take the following steps:

  1. Download the latest version of Smarty.
  2. Extract it under any directory you chose (e.g., /usr/local). This example will use [installation_dir] going forward.
  3. Create the directories [installation_dir]/smarty/templates_c and [installation_dir]/smarty/cache.

overLIB Installation
Here are the steps to install the overLIB JavaScript library (more on overLIB later):

  1. Download the overLIB zip file.
  2. Go to the [document_root] directory and run the following commands:
      mkdir overLIB
      cd overLIB
  3. Extract the overLIB zip file.

MySQL Installation
Create your MySQL database schema with this command:

mysqladmin –u[user] –p[password] <file_sharing.sql

Setting Configuration Variables
As the file inc.config.php in the source code download explains, there are global variables specific to local installation. Set these variables as suggested in Table 1 below.

Table 1. Suggested Settings for Configuration Variables: These are global variables specific to local installation.
Value Value
$smarty_include_path [installation_dir]/smarty/libs
$pear_include_path where PEAR installation copies MDB2.php file
$overlib_path /overLIB
$template_dir [document_root]/file_sharing/smarty/templates
$config_dir [document_root]/file_sharing/smarty/configs
$cache_dir [installation_dir]/smarty/cache
$compile_dir [installation_dir]/smarty/templates_c
$dsn mysql://db_user:db_password@db_server/file_sharing

When all the above installations are complete, you can call http://yourserver/file_sharing/file_sharing.php (see Figure 1) and start to upload files (see Figure 2).

Figure 1. File-Sharing Application Home Page: This figure shows the uploaded and tagged files with the list of used tags.
Figure 2. File-Sharing Action Pop-Up: This figure shows the pop-up opened after clicking on a file.

Author's Note: Versions 6 and 7 of Internet Explorer send the inner text of a button instead of its value, which is counter to the W3C recommendation. So if you would like to use these IE versions for this example, you have to replace all <button> instances in .tpl files with <input>, which will sacrifice some CSS benefits.

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