Home arrow PHP arrow Page 4 - Creating a Multi-File Upload Script in PHP
PHP

Creating a Multi-File Upload Script in PHP


Frustrated with single-file upload scripts? Looking for an alternate route? Read as Jonathan shows us how easy it really is to setup a multi-file upload script using PHP.

Author Info:
By: Jonathan Wichmann
Rating: 4 stars4 stars4 stars4 stars4 stars / 730
October 27, 2003
TABLE OF CONTENTS:
  1. · Creating a Multi-File Upload Script in PHP
  2. · Script 1: Number of Upload Boxes Required
  3. · Script 2: Creating the Dynamic Form
  4. · Script 3: The Big Copy Bang Page
  5. · Conclusion

print this article
SEARCH DEVARTICLES

Creating a Multi-File Upload Script in PHP - Script 3: The Big Copy Bang Page
(Page 4 of 5 )

processFiles.php

Here is the last page to complete our multiple upload tasks.

<?
$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
 // check if successfully copied
 if($copy){
 echo "$file_name | uploaded sucessfully!<br>";
 }else{
 echo "$file_name | could not be uploaded!<br>";
 }
} // end of loop
?>

The first thing we do in this page is grab the uploadNeed from uploadForm2.php. We setup our for loop in the same fashion as the last page. The difference here though is we get the $_FILES name within the for loop. I assign this to the local variable name $file_name.

Next, we do a little parsing by adding the stripslashes and str_replace functions. The reason we add the stripslashes is due to file that may have apostrophes in their name; otherwise this will generate a parse error and prevent that file from being uploaded.

Notice once again how I add the $x variable, which in turn is a number, to the name of the $_FILES. By doing this the script now knows which file it is uploading.

We will use the copy function now to actually begin the upload process. The last thing I added was a simple if statement to check that the copy was successful and I echo that message out to the screen.


blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- 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

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials