Return to Snippet

Revision: 10024
at December 3, 2008 14:23 by jadedbat

Initial Code
use this html for the upload form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>File Upload</title>
<style type="text/css">
body {font-family:Lucida Grande, "Lucida Sans", arial; font-size:1.3em; color:#555;}

<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <form action="upload_handle.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
      <td><table width="100%" border="0" cellpadding="8" cellspacing="8" bgcolor="#FFFFFF">
            <td><strong>Multiple File Upload:<br /><span style="font-size:70%;">(*you dont have to upload more than one.)</span></strong></td>
            <td> File One <br />
              <input name="ufile[]" type="file" id="ufile[]" size="50" />
            <td>File Two<br />
              <input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
            <td align="center"><input type="submit" name="Submit" value="Upload" /></td>



// define your paths below eg uploaded_files chmod that dir 777
$path1= "uploaded_files/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "uploaded_files/".$HTTP_POST_FILES['ufile']['name'][1];

// copy files to server
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);

// get sizes

// output file info upon success or throw error
if($filesize1 != 0){
	echo "File Name : ".$HTTP_POST_FILES['ufile']['name'][0]." was uploaded <br />"; 
	echo "File Size : ".$HTTP_POST_FILES['ufile']['size'][0]."<br />"; 
	echo "File Type : ".$HTTP_POST_FILES['ufile']['type'][0]."<br /><br />"; 
			echo "No File Uploaded <br /><br />";
// output file info upon success or throw error
if($filesize2 != 0){
	echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<br />"; 
	echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<br />"; 
	echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<br />"; 
		echo "2nd File Not Uploaded <br /><br />";


Initial URL

Initial Description
1. Edit the html form 'action' to point to your PHP page that handles the upload.
2. Create the php page with the code below
3. Define Paths in PHP lines:  3 , 4 of php file
4. Create matching folder to paths in #3 on server.
5. chmod that folder 777
6. Tweak to your liking.

Initial Title
PHP Multiple File Upload

Initial Tags
php, file

Initial Language