Page 1 of 1

uploading multiple files

Posted: Fri May 25, 2007 3:34 pm
by ioni
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi guys,

 Up to now I've needed mostly single file uploading via php, and there is plenty of examples on the net. I had no problem using and adapting those. However,  when trying the multiple file case, I've run into strange problems, even with adapted public code. 

 For example having a form like the one below:
 [syntax="html"] 
<form method="post" action="http://www. .... /upload.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<p class="sectionheader">Add New Event</p>
  <a href="javascript:window.history.back();">GO BACK (w/o making changes)</a><br><br>
        <table width="800" border="0" cellspacing="0" cellpadding="0">
          <tr> 
      		<td class="newsheader" valign="top">Main Picture 1 (only 514x396 pixels, default):</td>
      		<td><input name="uFiles[]" type="file" class="box" size="60"></td>
    	 </tr>
		 <tr> 
      		<td class="newsheader" valign="top">Main Picture 2 (only 514x396 pixels):</td>
      		<td><input name="uFiles[]" type="file" class="box" size="60"></td>
    	 </tr>
		 <tr> 
      		<td class="newsheader" valign="top">Main Picture 3 (only 514x396 pixels):</td>
      		<td><input name="uFiles[]" type="file" class="box" size="60"></td>
    	 </tr>
		 <tr> 
      		<td class="newsheader" valign="top">Main Picture 4 (only 514x396 pixels):</td>
      		<td><input name="uFiles[]" type="file" class="box" size="60"></td>
    	 </tr>
		 <tr> 
      		<td class="newsheader" valign="top">Main Picture 5 (only 514x396 pixels):</td>
      		<td><input name="uFiles[]" type="file" class="box" size="60"></td>
    	 </tr>
		 <tr> 
      		<td class="newsheader" valign="top">Main Picture 6 (only 514x396 pixels):</td>
      		<td><input name="uFiles[]" type="file" class="box" size="60"></td>
    	 </tr>

        </table>
        <br>
    
    <input type="Submit" name="submit" value="Enter">&nbsp;
    <input type="Reset" name="reset" value="Reset"></p>
    </form>
and a php file like this[/syntax]

Code: Select all

foreach ($_FILES["uFiles"]["error"] as $key => $error) {
     if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["uFiles"]["tmp_name"][$key];
        $name = $_FILES["uFiles"]["name"][$key];
        move_uploaded_file($tmp_name, "./$name");
    } else {
		print "$error " . "\r\n";
	}
}
I get a printed 4 4 (error codes - file not uploaded) result no matter how many files I load into the form. What's strange, beside not working, is that even I try to upload 4 or 5 files I still get only 2 error codes. Files are under the maximum size and I don't there any server issues (like Php settings and/or permissions). Or are they?
Any suggestions? What am I doing wrongly?
Thanks, Cristian


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]

Posted: Sat May 26, 2007 12:32 pm
by s.dot
Are you running PHP version 4.2 or greater?