Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


How do I make an Self-Server Log In, Upload and Download System?

I was trying to build off of my Blog, and I was curious on how to make a Server Log-in that allows only me to sign in and when i sign in. I would like to be able to have an Upload and Download File system that allows me to see the directory and download and upload files through the browser.

2 Answers

Hi Nathan,

You can build this "Administration System" from my understanding of your question by creating a MySQL Database with relevant database tables which will capture the information your trying to store. (I will link a reference on how to build a basic login system on which you can adapt to your requirements / needs.)

Once your MySQL database scheme has been built you can go ahead and start building the web application in PHP which will integrate into the MySQL database to send and receive data. (User Accounts, Upload Documents)

You can use store links in your MySQL Database of your uploaded documents and reference them as a hyperlink in a list or table format on which you can download your documents.

Reference Links:

// MySQL Connect - http://www.w3schools.com/php/php_mysql_connect.asp

// Basic PHP Login - http://code.tutsplus.com/articles/how-to-build-a-login-system-for-a-simple-website--net-2853

I hope this helps with getting started.

Regards, Liam Norris

Andrew McCormick
Andrew McCormick
17,730 Points

It's according to how extensive you need it.
Definitely going to use database for your login/log out.
As for file management, there are a few options:

  • you can store the location of the files in the database. for example your table might have a column for filename and then a column for the url to that filename. You would then use that information to retrieve and manage the files.

  • the other option is to simply use PHP to search a given folder and display the contents. For example I just used this exact code tonight to display a quick list of files:

//defining the directory I wanted to search
$upload_dir = wp_upload_dir();
$dir = $upload_dir['basedir'].'/order-exports';  

//opening the directory
                    $dh  = opendir($dir);

//beginning the HTML I want to serve up on the client side 
                 $selected = "<h1>Here are the Exports</h1>";

//using a while loop to pull filenames from the directory
                    while (false !== ($filename = readdir($dh))) {

                        $files[] = $filename;
  // using this method will also display "." and ".." which we want to avoid
                       if ($filename == '.' || $filename == '..') {

//display a link to each file
                       $selected .= '<a href="'.$upload_dir['baseurl'].'/order-exports/'.$filename.'">'.$filename.'</a><br/>';


// print the HTMl to the client
  echo $selected;

As far as getting the files to the server, I would suggest using Plupload: http://www.plupload.com/ . You will still need to handle the upload via php, but the Plupload is a great tool to use to upload the files through the front end of the site. See more details here about validation and handling the file on the server side: http://www.w3schools.com/php/php_file_upload.asp

hope that gets you started.