2016-10-04 37 views
2

我上傳圖像,並將其路徑或目錄存儲到成功存儲的數據庫,但現在當我從數據庫檢索圖像破碎的圖像加載在這裏plz幫助我出來提前感謝。我已經檢查了這些計算器的問題123在php中從Mysql檢索到的斷開的圖像?

我的顯示腳本

<?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)); \t 
 
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'; 
 
\t \t 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' />"; 
 

 
?>;

+1

我看不到任何地方在你的「顯示」代碼,你顯示你從圖像庫中檢索到的圖像。你只迭代結果,但從不使用$行結果? .. – DTH

+0

檢查它while($ row = mysqli_fetch_array($ sql,MYSQL_BOTH)){ ?> –

+1

您在顯示代碼中缺少據我所見 – DTH

回答

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)); \t 
 
while($row = mysqli_fetch_array($sql,MYSQL_BOTH)){ 
 
\t 
 
\t 
 
\t 
 
\t 
 
\t 
 
$row = mysqli_fetch_array($conn,$sql); 
 
     header("Content-type: " . $row["images_id"]); 
 
     echo $row["images_path"]; 
 
     } 
 
    mysqli_close($conn); 
 

 

 

 
?>

,並從已保存或存儲的路徑顯示它像

<?php 
 
include("configdb.php"); 
 
    function GetImageExtension($imagetype) 
 
    { 
 
     if(empty($imagetype)) return false; 
 
     switch($imagetype) 
 
     { 
 
      case 'image/bmp': return '.bmp'; 
 
      case 'image/gif': return '.gif'; 
 
\t \t 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' />"; 
 

 
?>;