PHP
  Home arrow PHP arrow Page 3 - Creating a Multi-File Upload Script in PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Creating a Multi-File Upload Script in PHP
By: Jonathan Wichmann
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 627
    2003-10-27

    Table of Contents:
  • Creating a Multi-File Upload Script in PHP
  • Script 1: Number of Upload Boxes Required
  • Script 2: Creating the Dynamic Form
  • Script 3: The Big Copy Bang Page
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More PHP Articles
    More By Jonathan Wichmann


       · Where do the files get uploaded to? I followed this line by line and all it does is...
       · This gives a great simple tutorial on how to use this script on your own server,...
       · I also copied all the instructions and it worked beautifully.The test files I...
       · Can someone please tell me how to change the location of uploaded...
       · the fiels will be uploaded to the directory where the source php files are...
       · mani want to make a form with upload and mail function.someone will write a...
       · This is the code for copying:$copy = copy($_FILES['uploadFile'....
       · For some of you who are still looking for another way to upload multiple files with...
       · The solution presnted is clumsy. Using Silver Light??! to me that's...
       · I copied the files to my server, took the liberty of renaming the php's as per our...
       · Check my demo project here -...
       · any suggestions how to streamline this code into just one page, where the 'select...
       · Demo & working code for Multi-file-upload PHP Script here:...
     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT