Page 1 of 1

Upload file not uploaidng

Posted: Wed Mar 30, 2011 7:52 pm
by jm00730
I have a form which i am using to upload two images, however for some reason my code isn't picking up that an image has been selected for upload . I get the following errors
Warning: copy() [function.copy]: Filename cannot be empty in /homepages/31/d250709875/htdocs/portal/productFunctions.php on line 173

Warning: copy() [function.copy]: Filename cannot be empty in /homepages/31/d250709875/htdocs/portal/productFunctions.php on line 174

Any help would be greatly appreciated!
Below is my code

form:

Code: Select all

<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="multiUpload.php" method="post"  name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>multiple Files Upload </strong></td>
</tr>
<tr>
<td>Select file 
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>

<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
php:

Code: Select all

//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "images/customHitches".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "images/customHitches".$HTTP_POST_FILES['ufile']['name'][1];

//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);


///////////////////////////////////////////////////////

// Use this code to display the error or success.

$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];


if($filesize1 && $filesize2 != 0)
{

	mysql_query("INSERT INTO customOrders (Cust_Name, Email, Phone, Base, Description, Logo_Image, FacePlate_Image)
			VALUES('$name', '$email', $phone'', '$base', '$description', '$path1', '$path2')")
			or die("Error Encountered while attempting to add custom order");	 
	$result=mysql_query($sql);
	
	// if successfully insert data into database, displays message "Successful".
	if($result){
		$to = "jose.martinez.it@gmail.com";
		$headers = "From:".$email;
		$subject = "Custom Hitch Order";
		$Message = "You have a Custom Hitch order from \n
		Name: '$name' \n
		Phone: '$phone' \n
		";
		
		mail($to,$subject, $message, $headers);
	echo "<a href='insert.php'>Back to main page</a>";
	}

else {
echo "ERROR";
}

// close connection
mysql_close();

Re: Upload file not uploaidng

Posted: Wed Mar 30, 2011 8:47 pm
by Weirdan
$HTTP_POST_FILES is an old way to access uploaded files (not really used since ages). Use $_FILES array instead.

Re: Upload file not uploaidng

Posted: Wed Mar 30, 2011 9:37 pm
by jm00730
Thanks for the quick response, I tried $FILES['ufile']['name'][0]; but am still getting the following error

Warning: copy() [function.copy]: Filename cannot be empty in /homepages/31/d250709875/htdocs/portal/productFunctions.php on line 173
Warning: copy() [function.copy]: Filename cannot be empty in /homepages/31/d250709875/htdocs/portal/productFunctions.php on line 174

any other ideas?

Re: Upload file not uploaidng

Posted: Wed Mar 30, 2011 10:33 pm
by fugix
its because in you form you havnt specified the proper enctype.... include enctype='multipart/form-data' in you <form> tag

Re: Upload file not uploaidng

Posted: Wed Mar 30, 2011 10:43 pm
by jm00730
thanks again for the quick responses, I have added the form enctype but i am still getting the error. just incase it makes a difference i have the form in a joomla article. whille my php code for uploading is in a seperate file located in the site root directory

Re: Upload file not uploaidng

Posted: Thu Mar 31, 2011 3:52 am
by Weirdan
jm00730 wrote:I tried $FILES['ufile']['name'][0];
It should be $_FILES, not $FILES . Underscore is important.

Re: Upload file not uploaidng

Posted: Thu Mar 31, 2011 2:05 pm
by fugix
i assumed that $FILES was just a mistype...but yes if you put $FILES instead of $_FILES it will not execute the array