我怎样才能做一个允许用户上传图片的php和xhtml表单以及提交所有数据后发送到我的电子邮箱?
答案 0 :(得分:3)
在Google上搜索教程并自己学习。这个问题在本网站上发布的问题太广泛了。自己尝试一下,如果你能提出具体的问题,你就没有答案,请在这里问一下。这是让你入门的东西:
答案 1 :(得分:0)
主要的PHP网站本身也包含一些关于推荐做法和陷阱的好信息,以及一些示例代码 - 请参阅“Handling file uploads”部分。
答案 2 :(得分:0)
试试这个
<?
//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";
}
}
?>