2017-06-15 68 views
0

enter image description here我想將文件夾中的圖像顯示到網頁上。圖像目錄已經保存在數據庫中。 MySQL查詢是正確的。該語法可以顯示圖像目錄,但無法顯示圖像。使用文件目錄從數據庫中顯示圖像

<?php session_start(); ?> 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<!-- The above 3 meta tags *must* come first in the head; any other head 
content must come *after* these tags --> 
<title>Profile |CRB</title> 

<!-- Bootstrap --> 
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet"> 

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media 
queries --> 
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
<!--[if lt IE 9]> 
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"> 
</script> 
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"> 
</script> 
<![endif]--> 
</head> 


<body> 
<?php include 'header.php' ?> 
<ul class="nav nav-tabs">     <!-- NAV TABS --> 
<li role="presentation"><a href="index.php">Home</a></li> 
<li role="presentation"><a href="trucks.php">Trucks</a></li> 
<li role="presentation"><a href="suppliers.php">Suppliers</a></li> 
<li role="presentation"><a href="clients.php">Clients</a></li> 
<li role="presentation"><a href="services.php">Services</a></li> 
<li role="presentation"><a href="accountspayables.php">Uploaded Files</a> 
</li> 
<li role="presentation"><a href="maintenance.php">Maintenance</a></li> 
<!-- DROPDOWN start --> 
<li role="presentation" class="dropdown"> 
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" 
aria-haspopup="true" aria-expanded="false"> 
    About us <span class="caret"></span> 
</a> 
<ul class="dropdown-menu"> 
    <li role="presentation"><a href="contactus.php">Contact us</a></li> 
    <li role="presentation"><a href="aboutus.php">About us</a></li> 
</ul> 
</li> 
<!-- END OF DROPDOWN --> 
<?php 
if(isset($_SESSION['started']) && $_SESSION['started']) { 

} 
?> 

<li role="presentation" class="dropdown pull-right"> 
<a class="dropdown-toggle" data-toggle="dropdown" href="" role="button" 
aria-haspopup="true" aria-expanded="true"> 
    <span class="glyphicon glyphicon-user" style="cursor: pointer;" aria- 
hidden="true"> <span class="caret"></span> 
</a> 
<ul class="dropdown-menu"> 
    <li role="presentation"><a href="">Settings</a></li> 
    <li role="presentation"><a href="logout.php">Log out</a></li> 
</ul> 
</li> 

<li class="pull-right" class="active"><a href="profile.php"><?php echo 
$_SESSION['user'];?></a></li> 
</ul> 
<!-- end of HEADER --> 
<br> 
<div class="row"> 
<div class="col-sm-4"> 

<?php include 'config.php'; 
if(isset($_SESSION['started']) && $_SESSION['started']) { 

} 
$val = ''; 
$query="SELECT USER_PHOTOPATH FROM useraccounts WHERE USER_NAME = 
'".$_SESSION['user']."' "; 
$stmt = $conn->prepare($query); 
$stmt -> bindParam(1,$val); 
$stmt -> execute(); 

$row = $stmt->fetch(PDO::FETCH_ASSOC); 
echo $row['USER_PHOTOPATH']; 
?> 

<img src="<?php echo $row['USER_PHOTOPATH']; ?>;"> <!-- I TRIED THIS SYNTAX 
TO DISPLAY THE IMAGE --> 
</div> 

<?php 

?> 
<div class="col-sm-4"> 

<h1 class="text-primary">My Profile</h1> 

<div class="col-sm-4"></div> 
</div> 

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> 
</script> 
<!-- Include all compiled plugins (below), or include individual files as 
needed --> 
<script src="bootstrap/js/bootstrap.min.js"></script> 
</body> 
</script> 
</html> 
+0

後向我們展示一個'回聲$行[「USER_PHOTOPATH」];'所以我們可以看到的是什麼,你已經存儲在數據庫中 – RiggsFolly

+0

一個例子你能解釋這個代碼是否存在'if(isset($ _ SESSION ['started'])&& $ _SESSION ['started']){ },因爲它看起來什麼都不做 – RiggsFolly

+0

你檢查過圖像路徑嗎? –

回答

0

請刪除;完成?> PHP <img src="<?php echo $row['USER_PHOTOPATH']; ?>;">

+0

謝謝,我沒注意到 –