Creating a Multi-File Upload Script in PHP
Frustrated with single-file upload scripts? Looking for an alternate route? Read as Jonathan shows ushow easy it really is to setup a multi-file upload script using PHP.As a PHP programmer I had run into a problem where a client needed a form to upload more than onefile at a time. So one night I sat down and spent an hour figuring out the best and easiest way to dothis. In this tutorial, the
for loop
is going to be your best friend.
Creating a Multi-File Upload Script in PHP -Script 1: Number of Upload Boxes Required
uploadForm1.php
<html><head><title># of Files to Upload</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><form name="form1" method="post" action="uploadForm2.php"><p>Enter the amount of boxes you will need below. Max = 9.</p><p><input name="uploadNeed" type="text" id="uploadNeed" maxlength="1"></p><p><input type="submit" name="Submit" value="Submit"></p></form></body></html>
As you can see this first page is very basic. In my form I set the uploadNeed maxlength to 1. This waythe max upload boxes he or she can get is 9. You can increase or decrease this to satisfy your own project needs.
Creating a Multi-File Upload Script in PHP -Script 2: Creating the Dynamic Form
uploadForm2.php
Ok, this page will be doing one half of the work. We will be using the for loop to get this task done.
<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><form name="form1" enctype="multipart/form-data" method="post"action="processFiles.php">
Add a Comment