StormyVids – Creating a File Storage Site

Lua Script Code

Sharing is caring!

StormyVids is a new website I created to allow me to upload any type of file to the web and allow me to download it from anywhere with internet access. I created the site because I was sick of using my old .htaccess password protected folder on my web server. Having to manually enter username and passwords each time I wanted access to the media was a pain and I couldn’t link people to the media without creating new users.

What I was aiming for.

I wanted a server that would allow me to upload any type of file without the file causing security issues when uploaded. I also wanted to be able to get a link for each item I uploaded so I could either post them in emails or have on a wiki. Access to files directly should be disallowed so people can’t browse all the files that have been uploaded. I also wanted it so colleagues could upload and share media with me.


How the StormyVids site is structured.

StormyVids is made from 2 web pages and 3 scripts. The 2 web pages are the upload and download pages and the 3 scripts are the upload, download and dropzone scripts. The upload and download scripts are both written in PHP and the dropzone script is a Javascript library available from which allows the user to drop files directly onto a webpage to initiate the upload.

The StormyVids upload script.

The upload script is designed to accept files from the PHP $_FILES variable which contains an associative array of items uploaded to the current script via the HTTP POST method. Once the $_FILES data is loaded the file is moved to the uploaded files folder outside of the web root so end users cannot access them without the download script.A connection is then made to the database which stores the name of the file, the temp name of the file, the mime type and a hash value which is used in the download link to identify the file to be downloaded. This is added to the database using a prepared statement to limit SQL injections. Once all this is done checks are made to see if any parts failed and show an error message if any errors occur.

The basic version of the StormyVids upload script is shown below:

The StormyVids Download script

The download script uses the data from the database to select the file from the uploaded file directory, set the mime-type and start the download of the file. This is done by using the PHP $_GET parameter which supplies the unique hash value that identifies which file to download. Once the hash is retrieved the download script gets the data for that file from the database. This data includes the original name of the file, the mime-type and the stored name of the file. The script then uses the header method to set the mime-type of the file and then reads the file using the php method readfile(). Here we use a unique has to identify the file so users are not aware of the file name on the server. This reduces the risk of hackers running scripts on the server which could lead to undesired access.

Below is the basic version of the StormyVids download script:


The StormyVids Web pages.

There is 2 web pages used in the StormyVids site. One for upload and one for download. The upload page uses dropzone to create a box on the page where the user can drop a file and the upload will begin automatically. A dropzone event is fired once the file has completed it’s upload which then retrieves the HTTP response from the upload script and displays it in the return divider.

StormyVids Upload Web Page:

The download page uses a JavaScript timer to start the download 10 seconds after loading. Once the timer has counted down an iframe is created with JavaScript that’s source is the download script with the unique hash of the file to be downloaded. This then starts the download process, yay! you have downloaded the file.

Here is the code for the download web page:

Further Reading:

Sharing is caring!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.