我无法将图像移动到C:\ wamp64 \ www \ mywork \ images。
上传图片后,数据库中有一条记录。但是,当我检查我的C:\ wamp64 \ www \ mywork \ images文件夹时,图像不会移动。有人可能会怀疑,可能是我的$ target路径错了。我已多次尝试但仍然无法正确使用。
数据库结果:https://flic.kr/p/YZsQva
文件夹我试图将我的图片放入:https://flic.kr/p/YGHRLQ
<?php
$db = mysqli_connect("localhost", "root", "", "mywork");
$msg = "";
if (isset($_POST['upload'])) {
$target = "/mywork/images/".basename($_FILES['image']['name']);
$image = $_FILES['image']['name'];
$sql = "INSERT INTO movie (image) VALUES ('$image')";
mysqli_query($db, $sql);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$msg = "Image uploaded successfully";
}else{
$msg = "Failed to upload image";
}
}
$result = mysqli_query($db, "SELECT * FROM movie");
?>
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<div id="content">
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
echo "<img src='/mywork/images".$row['image']."' >";
echo "</div>";
}
?>
<form method="POST" action="manage.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image">
</div>
<div>
<button type="submit" name="upload">POST</button>
</div>
</form>
</div>
</body>
</html>