我有一个这样的表单,我想知道是否有办法添加图像输入并将其上传到服务器。
我希望能够将图像上传到[ROOT] / upload_img /但是,说实话我不知道该怎么做,而且我发现的大多数代码部分都不适合我...
我在这里。
这是我的代码:
<html>
<head></head>
<body>
<div id="main">
<div id="login">
<form action="" method="post">
<label>Titre de l'annonce :</label>
<input type="text" name="i_title" id="name" required="required" placeholder=""/>
<br />
<br />
<label>Adresse : </label>
<input type="text" name="i_adress" id="email" required="required" placeholder=""/>
<br/>
<br />
<label>Ville :</label>
<input type="text" name="i_city" id="city" required="required" placeholder="Please Enter Your City"/>
<br/>
<br />
<label>Surface du logement entier :</label>
<input type="text" name="i_surf_room" id="surf_room" required="required" placeholder=""/> En m2
<br/>
<br />
<label>Surface de la chambre :</label>
<input type="text" name="i_surf_home" id="surf_home" required="required" placeholder=""/>
<br/>
<br />
<label>Description :</label>
<input type="text" name="i_description" id="description" required="required" placeholder=""/>
<br/>
<br />
<label>Date de début de disponibilité :</label>
<input type="month" name="i_start_date" id="start_date" required="required" placeholder=""/>
<br/>
<br />
<label>Date de fin de disponibilité :</label>
<input type="month" name="i_end_date" id="end_date" required="required" placeholder=""/>
<br/>
<br />
<label>Photographies du logement</label>
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="reset"> -
<input type="submit" name="submit"/>
<br />
</form>
</div>
</div>
<?php
if(isset($_POST["submit"])) {
$hostname='xxxx';
$username='xxxx';
$password='xxx';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=xxxx",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "INSERT INTO students (title, adress, city, surf_home, surf_room, description, start_date, end_date)
VALUES ('".$_POST["i_title"]."','".$_POST["i_adress"]."','".$_POST["i_city"]."','".$_POST["i_surf_home"]."','".$_POST["i_surf_room"]."','".$_POST["i_description"]."','".$_POST["i_start_date"]."','".$_POST["i_end_date"]."')";
if ($dbh->query($sql)) {
echo "
<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>";
} else {
echo "
<script type= 'text/javascript'>alert('Data not successfully Inserted.');</script>";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
</body>
</html>