我想添加文件上傳到我當前的代碼。我有很好的形式,不希望改變它。我一直在搜索谷歌和YouTube,無法找到我可以添加到我的當前代碼的代碼。當我所得到的錯誤是錯誤時,這是如此令人沮喪。與文件上傳聯繫表格
<?php
if ($_POST['submit']) {
if (!$_POST['username']) {
$error = "<br>- Please enter your name! \r\n";
}
if (!$_POST['email']) {
$error .= "<br>- Please enter your email! \r\n";
}
if (!$_POST['message']) {
$error .= "<br>- Please enter your message! \r\n";
}
if ($error) {
$result = "<div class='alert alert-danger' role='alert'>Whoops, there is an error. Please correct the following: $error</div>";
} else {
mail("[email protected]", "Message from contact form", "From: ".$_POST['username']."
Reply to: ".$_POST['email']."
Message: ".$_POST['message']);
{
$result = "<div class='alert alert-success text-center' role='alert'>
<p>Thank you for your message. We will contact you socket_get_option(socket, level, optname)</p>
</div>";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Title</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<section>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-4 col-sm-offset-4">
<h1 class="text-center">Contact us</h1>
<?php echo $result;?>
<form action="material.php" method="post" role="form">
<div class="form-group input-group input-group-lg">
<span class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
</span>
<input type="text" name="username" class="form-control">
</div>
<div class="form-group input-group input-group-lg">
<span class="input-group-addon">
<span class="glyphicon glyphicon-envelope"></span>
</span>
<input type="email" name="email" class="form-control">
</div>
<div class="form-group">
<textarea name="message" id="message" rows="5" placeholder="Message box"></textarea>
</div>
<p>Send us your photo</p>
<div>
<input type="file" name="file" enctype="multipart/form-data">
</div>
<div class="form-group input-group btn-margin">
<span class="input-group-addon">
<span class="glyphicon glyphicon-send"></span>
</span>
<input type="submit" name="submit" class="form-control btn btn-primary" value="Submit request">
</div>
</form>
</div>
</div>
</div>
</section>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
那麼,就是你正在努力處理是給你「在錯誤的錯誤」的文件上傳的代碼?我沒有看到那裏試圖處理文件的東西。 –