2014-10-20 113 views
0

我想寫新聞系統到我的網站,我將上傳圖像到服務器上的文件夾,並將此圖像鏈接添加到MySQL。最後在現場顯示文字和圖像。 我知道如何在服務器上上傳文件,但以後要做什麼......我不知道。 有人可以幫助我嗎? 我不需要準備好腳本,只是一些提示如何做到這一點。PHP/MYSQL圖像上傳到服務器鏈接到mysql

+2

只是圖像名稱保存到數據庫中,由於路徑圖像將保持不變。當顯示圖像時,使用'echo「」'顯示圖像 – Justinas 2014-10-20 10:58:42

+0

謝謝,我對php和mysql非常沒有經驗,所以我甚至沒有想過這麼簡單的方法。 – Shinri 2014-10-20 11:10:25

回答

0

既然你提到你已經保存在數據庫中的鏈接..

只需做到以下幾點:

<img src="/uploads/<?php echo $imglink;?>"> 
0
在腳本

上傳你應該在數據庫中添加的插件,例如上傳.PHP:

// script upload : 
// .... 
// .... 
// .... 
$description = "your text for image"; 
//$image_name : name extracted from path image. 

// script insert : 
$stmt = $dbh->prepare ("INSERT INTO table_name (description, image) VALUES (:description, :image)"); 
$stmt -> bindParam(':description', 'John'); 
$stmt -> bindParam(':image', $image_name); 
$stmt -> execute(); 

以查看例如導致list.php的:

//======================================== 
$query = "SELECT * FROM table_name"; 
$stmt = $dbh->prepare($query); 
$stmt->execute(); 
$rows = $stmt->fetchAll(); 

// Print results : 
foreach ($rows as $row) { 
    echo $row["description"] . "<br/>"; 
    echo "<img src='path/to/img".$row['image']."'/>" 
} 
0

試試這個

 $query=mysql_query("select * from image"); 

while($row=mysql_fetch_array) 
{ 
echo "<img src='/uploads/'".$row['imglink']."' height='200' width='200'>" 
}