下面有一段代码(imageupload.php),php假设将文件上传到服务器并将数据插入数据库。
<?php
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
die();
}
$result = 0;
//UPLOAD IMAGE FILE
move_uploaded_file($_FILES["fileImage"]["tmp_name"], "ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
//INSERT INTO IMAGE DATABASE TABLE
$imagesql = "INSERT INTO Image (ImageFile) VALUES (?)";
if (!$insert = $mysqli->prepare($imagesql)) {
// Handle errors with prepare operation here
}
//Dont pass data directly to bind_param store it in a variable
$insert->bind_param("s", $img);
//Assign the variable
$img = 'ImageFiles/' . $_FILES['fileImage']['name'];
$insert->execute();
$insertimagequestion->execute();
//IF ANY ERROR WHILE INSERTING DATA INTO EITHER OF THE TABLES
if ($insert->errno) {
// Handle query error here
}
$insert->close();
}
?>
但是我想创建html表单来关联这个,但我从未在html中创建过文件输入。有没有人知道如何创建与此相关的html表单?
我想要一个HTML代码,以便我可以测试上面的代码,然后能够测试是否有任何错误。
答案 0 :(得分:0)
您可以按以下方式制作HTML表单:
<form action="http://www.example.com/upload.php"
enctype="multipart/form-data" method="post">
<p>
Please specify a file, or a set of files:<br>
<input type="file" name="fileImage" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>