Open Directory Download PHP Script

The other day I wanted to download multiple files from one open web directory. Now when I refer to an “open web directory” I mean a folder or directory on a website that does not contain an index file and has the permissions set so any user can view the files in that directory. Instead of clicking “Save Target As…” for each file I decided to write a script in PHP that would grab all the files and store them in a folder of my choice.

Why did I choose PHP for this? Because PHP is the only programming language I am familiar with enough that I knew could accomplish the task. I can probably guarantee that there is a better language for this type of script, however my sole goal is to make the process of grabbing these files more efficient and PHP will help me accomplish that. I am using an install of WAMPServer to execute the PHP script. Here is the code:

There are fields for the URL of the directory you want to download, the folder you want to create to store the files (the folder will be created in the same directory as the script), and a timeout time in case the script gets caught in a loop.

Now the script isn’t all encompassing; it won’t loop through any subdirectories;it won’t discriminate by filetype;special characters can ruin it; and more. However, the script can be modified to accomplish all that if that’s what you wish. The only catch I wrote in to the script was to replace “%20″ with a space wherever applicable.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">