Uploading multiple files to a web server

How to upload multiple files to a web server

When I recently moved house I had to go three weeks without broadband. In it’s place I used a 3G modem in order to be able to keep running my business. It felt like going back to the 56k modem days at times, but it was tolerable for a short period.

One thing I did struggle with however was uploading multiple files to a remote web server. I usually upload WordPress other applications to web servers at least once per day which include thousands of files – that’s thousands of individual requests, giving my FTP client more opportunities, especially with slower upload speeds, to timeout.

So, instead of uploading multiple files I zipped them all into one file and transfers them onto the server. I then unzip them on the server using a PHP function, which takes seconds.

Here’s how I did it:

  1. Zip the files up into a file call it myfile.zip
  2. Upload myfile.zip to the folder on your web server into the correct folder.
  3. Create a PHP file named unzip.php in the same folder as your zip file with the following in it:
    <?php
    $zip = new ZipArchive;
    $location = $_SERVER['DOCUMENT_ROOT'];
    $zip->open('myfile.zip');
    $zip->extractTo("/$location/");
    $zip->close();
    ?>
  4. RUN unzip.php from your web browser and it will instantly unzip all the files.
  5. For security purposes delete myfile.zip and unzip.php from your server so nobody else can unzip files on your server.

And that’s about it. It was a massive time saver me for and increased the stability of my uploads over a slower internet connection.

 

Posted on September 3, 2011 in Content Management, Web Development, WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *

*

HTML tags are not allowed.