Page 1 of 1

Uploading more than one file!

Posted: Wed Jul 28, 2004 10:22 pm
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)

Posted: Wed Jul 28, 2004 11:19 pm
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;

Posted: Thu Jul 29, 2004 12:09 am
by kettle_drum
Also check for silly naming misakes in your html form.