Creating a Multi-File Upload Script in PHP - Script 2: Creating the Dynamic Form
(Page 3 of 5 )
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">
<p>
<?
// start of dynamic form
$uploadNeed = $_POST['uploadNeed'];
for($x=0;$x<$uploadNeed;$x++){
?>
<input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>">
</p>
<?
// end of for loop
}
?>
<p><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
In this page, all I did was create a simple HTML form with the value of the attribute "type" set to "file". Within the form I put a block of code to start the for loop. I set $x to 0 and I made it stop at the desired need by setting $x to be less than $uploadNeed – the value specified by the user. I also echo the $uploadNeed into a hidden input field to be carried over to the last page.
The key to making this all work however is the $x variable I am echoing right next to the uploadFile name. What this will do is append a number starting with 0 to the name. This in turn will make each upload field’s name unique.
Next: Script 3: The Big Copy Bang Page >>
More PHP Articles
More By Jonathan Wichmann
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|