Uploading more than one file!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Uploading more than one file!

Post by Joe »

I am looking for a way to solve a problem which I just cannot seem to figure out. I have two upload fields where users can upload two files per time but it only uploads the first one and says, "Could not copy!" for the second. My code go's like:

Code: Select all

if ($_FILES['file1'] != "")
{
 if ($_FILES['file1']['size'] < "20000")
 {
  copy ($_FILES['file1']['tmp_name'], $FinalImage."/".$_FILES['file1']['name']) or die ("Could not copy file. Please try again!");
 }
}

if ($_FILES['file2'] != "")
{
 if ($_FILES['file2']['size'] < "20000")
 {
  copy ($_FILES['file2']['tmp_name'], $FinalImage."/".$_FILES['file2']['name']) or die ("Could not copy file. Please try again!");
 }
}
It's a very simple script but cannot work it out :(

Any help appreciated.


Joe 8)
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Try this.

Code: Select all

if (isset($HTTP_POST_FILES['file1']['tmp_name'])) $file_name = $HTTP_POST_FILES['file1']['name'];
		else $file_name = "";
	if (isset($HTTP_POST_FILES['file2']['tmp_name'])) $file_name2 = $HTTP_POST_FILES['file2']['name'];
		else $file_name2 = "";

if (is_uploaded_file($HTTP_POST_FILES['file1']['tmp_name']))
	{
	copy($HTTP_POST_FILES['file1']['tmp_name'], , $FinalImage."/".$file_name);
	}
	if (is_uploaded_file($HTTP_POST_FILES['file2']['tmp_name']))
	{
	copy($HTTP_POST_FILES['file2']['tmp_name'], $FinalImage."/".$file_name2);
	}
#debug.. 
echo $file_name; echo $file_name2;
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Also check for silly naming misakes in your html form.
Post Reply