PHP Image Upload?

Hi All

Im trying to add a image(s) upload on a form but cant get it to work. I think my html is right, its the php form Im having the trouble with.

Can someone help. Here the code

Html:
<form enctype=“multipart/form-data” method=“POST” action=“listings.php”>

Country
<input type=“text” name=“country_of_business” value=“" size=“40”><br>
Regional area
<input type=“text” name=“regional_area” value="
” size=“40”><br>
Local area
<input type=“text” name=“local_area” value=“*” size=“40”><br>
<br>

<input type=“file” name=“imgfile” id=“imgfile” style=“background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey” value=“Browse” /><br />
<input type=“file” name=“imgfile” id=“imgfile” style=“background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey” value=“Browse” /><br />
<input type=“file” name=“imgfile” id=“imgfile” style=“background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey” value=“Browse” /><br />
<input type=“file” name=“imgfile” id=“imgfile” style=“background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey” value=“Browse” /><br />
<input type=“file” name=“imgfile” id=“imgfile” style=“background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey” value=“Browse” />

<input type=“submit” value=“Submit” name=“submit”>
</form>

PHP:
<?php
if(isset($_POST[‘submit’])) {

$to = "me@gmail.com";
$subject = "listing";

$option = $_POST['radio'];
$country_of_business_field = $_POST['country_of_business'];
$regional_area_field = $_POST['regional_area'];
$local_area_field = $_POST['local_area'];

HERES GOES THE IMAGE UPLOAD PART WHICH I KEEP MESSING UP

END
echo “Your details have been successfully submitted - Click the ‘back button’ to return to the previous page”;
mail($to, $subject, $body);

} else {
echo “blarg!”;
}
?>

Thanks in advance

There is a lot to mess up with uploading, so you are going to have to tell us what went wrong exactly.

Also, it might help if you distill your problem down to the simplest use-case possible, create a new form handler that does not delve into emails etc.

The key events to snag are:

Did your file upload at all?
What error messages are being spewed out?
Did you move your file from the temp directory to somewhere useful?

This is one area where you really go through the manual pages with a fine tooth comb, it tells you how to do all of this stuff because it can be time consuming to understand, and do securely.

http://www.php.net/manual/en/features.file-upload.php

See especially common pitfalls

Hi
This should work for your html. You have to create a directory named uploads in the same directory where this script file is.


if(isset($_POST['submit'])) {

//uploading code
for($i=0;$i<count($_FILES['imgfile']['name']);$i++){
	//this directory must be writeable
	$dir="uploads/";
	$filepath=$dir.$_FILES['imgfile']['name'][$i];
	move_uploaded_file($_FILES['imgfile']['tmp_name'][$i],$filepath);
}

$to = "me@gmail.com";
$subject = "listing";

$option = $_POST['radio'];
$country_of_business_field = $_POST['country_of_business'];
$regional_area_field = $_POST['regional_area'];
$local_area_field = $_POST['local_area'];


echo "Your details have been successfully submitted - Click the 'back button' to return to the previous page";
mail($to, $subject, $body);

} else {
echo "blarg!";
}


```php
$flag=0;
$imgflag=0;//for image format verification flag
 if(isset($imgfile[0])&&($imgfile[0]!="")&&(($HTTP_POST_FILES['imgfile[0]']['type']!="image/gif")&& ($HTTP_POST_FILES['imgfile[0]']['type']!="image/jpeg")))
$imgflag=1;
//if the format of image is not matched
if($imgflag==1)
	 {
		 print&lt;&lt;&lt;END
		 &lt;script language="Javascript"&gt;
		 alert("Image files should be of gif/jpeg format");
		 history.go(-1);
		 &lt;/script&gt;
		 END;
	 }
//if u want to insert into database:)
if(isset($imgfile[0])&&($imgfile[0]!=""))
	 {
	 $flag=1;
	 $img0 = $HTTP_POST_FILES['imgfile[0]']['name'];
	 $query1 = "update table_name set image='$img0' where condition";
	 $result1=mysql_query($query1);
	 if(!$result1) die('Invalid Query: '. mysql_error());
	 }


//if it shows some syntax errors but it is working
END
	echo "Your details have been successfully submitted - Click the 'back button' to return to the previous page";
	mail($to, $subject, $body);

} else {
	echo "blarg!";
}
?&gt;


Thanks in advance[/QUOTE]