我上传图像并将其路径或目录存储到成功存储的数据库中但是现在当我从数据库中检索图像时,图像加载这里plz帮助我提前感谢。我已经检查了这些stackoverflow问题 1 2和3
我的显示脚本
<?php
include("configdb.php");
$select_query = "SELECT 'images_path' FROM `images_tbl` ORDER by 'images_id' DESC";
$sql = mysqli_query($conn,$select_query) or die(mysqli_error($conn));
while($row = mysqli_fetch_array($sql,MYSQL_BOTH)){
}
?>
并上传脚本
<?php
include("configdb.php");
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "../Photos/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {
$query_upload="INSERT into images_tbl (`images_path`,`submission_date`) VALUES
('".$target_path."','".date("Y-m-d")."')";
mysqli_query($conn,$query_upload) or die("error in $query_upload == ----> ".mysqli_error($conn));
}else{
exit("Error While uploading image on the server");
}
}
echo "<img src='displayupload.php?id=7' width='200 px' height='200px' />";
?>;
答案 0 :(得分:2)
试试这个
<?php
include("configdb.php");
$select_query = "SELECT 'images_path' FROM `images_tbl` ORDER by 'images_id' DESC";
$sql = mysqli_query($conn,$select_query) or die(mysqli_error($conn));
while($row = mysqli_fetch_array($sql,MYSQL_BOTH)){
$row = mysqli_fetch_array($conn,$sql);
header("Content-type: " . $row["images_id"]);
echo $row["images_path"];
}
mysqli_close($conn);
?>
&#13;
并从您保存或存储的路径中显示
<?php
include("configdb.php");
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "../Photos/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {
$query_upload="INSERT into images_tbl (`images_path`,`submission_date`) VALUES
('".$target_path."','".date("Y-m-d")."')";
mysqli_query($conn,$query_upload) or die("error in $query_upload == ----> ".mysqli_error($conn));
}else{
exit("Error While uploading image on the server");
}
}
echo "<img src='../Photos/$imagename' width='200 px' height='200px' />";
?>;
&#13;