如何从我的上传路径文件夹所在的数据库中获取我的图像?
how to fetch my image from my database where my upload path folder?
我已经在 Whosebug 中查找过类似的问题。但它不会只对我有效。
问题可能出在我如何将图片上传到文件夹中?
这是 Whosebug 中的常见答案,他们说它有效,但它对我不起作用,图像仍会显示损坏。
Ps。如果问题不够具体,我很抱歉。这是我在 Whosebug
中的第一个问题
这只是我所拥有的示例:
<?php
include('session.php');
$query = mysqli_query($link, "SELECT * from tbl_menu");
while($res = mysqli_fetch_array($query)){
echo "<img src='Image_name/".$res['image']."'>";
}
?>
这是我上传图片的方式:
<?php
include_once('connect.php');
if(isset($_POST['AddMenu'])){
$uploadimage = 'C:/xampp/htdocs/thesis/Images_name/'.$_FILES["image"]["name"];
$mname =$_POST['mname'];
$price =$_POST['price'];
$mcategory =$_POST['mcategory'];
$image =$_FILES['image']['name'];
mysqli_query($link, "INSERT into tbl_menu(mname, price, mcategory, image) values('$mname', '$price', '$mcategory', '$image')");
if (move_uploaded_file($_FILES["image"]["tmp_name"], $uploadimage)) {
$msg = "image upload";
}else {
$msg = "not upload";
}
header("location: menu.php");
}
?>
echo "<img src='http://localhost/thesis/Image_name/".$res['image']."'>";
我建议您在主配置文件中将变量 "home" 保存为“http://localhost/thesis/”。并在需要的地方使用该变量。
我已经在 Whosebug 中查找过类似的问题。但它不会只对我有效。
问题可能出在我如何将图片上传到文件夹中? 这是 Whosebug 中的常见答案,他们说它有效,但它对我不起作用,图像仍会显示损坏。
Ps。如果问题不够具体,我很抱歉。这是我在 Whosebug
中的第一个问题这只是我所拥有的示例:
<?php
include('session.php');
$query = mysqli_query($link, "SELECT * from tbl_menu");
while($res = mysqli_fetch_array($query)){
echo "<img src='Image_name/".$res['image']."'>";
}
?>
这是我上传图片的方式:
<?php
include_once('connect.php');
if(isset($_POST['AddMenu'])){
$uploadimage = 'C:/xampp/htdocs/thesis/Images_name/'.$_FILES["image"]["name"];
$mname =$_POST['mname'];
$price =$_POST['price'];
$mcategory =$_POST['mcategory'];
$image =$_FILES['image']['name'];
mysqli_query($link, "INSERT into tbl_menu(mname, price, mcategory, image) values('$mname', '$price', '$mcategory', '$image')");
if (move_uploaded_file($_FILES["image"]["tmp_name"], $uploadimage)) {
$msg = "image upload";
}else {
$msg = "not upload";
}
header("location: menu.php");
}
?>
echo "<img src='http://localhost/thesis/Image_name/".$res['image']."'>";
我建议您在主配置文件中将变量 "home" 保存为“http://localhost/thesis/”。并在需要的地方使用该变量。