我想改变我的$target目录,目前在php/images/上传/images/,但由于某种原因,它不会工作,因为某些原因,没有图片上传到该文件夹,但仅限于php/images,我不知道是什么原因导致这一点。
我上传的所有图片都会上传到phpmyadmin,并加载到myimages.php页面,因此$target的所有工作都不起作用。
<?php
$db = mysqli_connect("localhost", "root", "", "media");
$msg = "";
if (isset($_POST['upload'])) {
$image = $_FILES['image']['name'];
$target = "php/images/".basename($image);
$sql = "INSERT INTO images (image_name) "
. "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";
}
}
?>
<form id='imageForm' method="POST" action="" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div>
<input class="file-upload" type="file" name='image' accept='image/*' />
</div>
<div class="upload-button">
<button class="" name='upload'>UPLOAD</button>
</div>
</form>
图片.php
$db = mysqli_connect("localhost", "root", "", "media");
$uploaded = mysqli_query($db, "SELECT * FROM images");
while ($row = mysqli_fetch_array($uploaded)) {
echo "<ul class='img_container'>";
echo "<li><img class='img_box' src='php/images/".$row['image_name']."' ></li>";
echo "</ul>";
}
1条答案
按热度按时间svgewumm1#
在mysql数据库中插入blob时,可以使用blob(base64),但如果加载的图像太多,则会减慢网站的运行速度,请看这里
还要检查您是否有权在该目录上写入。