How can I do a php and xhtml form that allows users to upload images and on submitting all the data is send to my e-mail?
+2
A:
By searching for tutorials on Google and learing it yourself. This is too broad a question to post on this site. Try it out yourself, and if you can come up with an specific question you don't have the answer for, ask it here. Here's something to get you started:
Tatu Ulmanen
2010-01-10 15:36:18
A:
The main PHP site itself also includes some good information on the recommended practices and pitfalls, as well as some sample code - see the 'Handling file uploads' section.
middaparka
2010-01-10 15:40:04
A:
Try this
<?
//print_r($_POST);
if($_POST["action"] == "Upload Image")
{
unset($imagename);
if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;
if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";
$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;
if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";
if(empty($error))
{
$newimage = "images/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
}
?>
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
<p><input type="file" name="image_file" size="20"></p>
<p><input type="submit" value="Upload Image" name="action"></p>
</form>
<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?>
streetparade
2010-01-10 15:48:01