我可以成功上傳圖片在我的數據庫,但是當我想在我的應用程序,以顯示他們有一個與圖像的問題。這裏是我的代碼部分:PHP不能顯示圖像
編輯:添加add_image.php
的index.php
<?php
session_start();
include("config.php");
$query = mysql_query("SELECT * FROM images");
$numrows = mysql_num_rows($query);
if($numrows != 0) {
while($row = mysql_fetch_assoc($query)) {
$title = $row['TITLE'];
$id = $row['ID'];
$image = $row['IMAGE'];
echo $title;
echo "<img src=image.php?id=$id>";
echo("<hr/><br/><br/>");
}
} else {
die("ERROR");
}
?>
image.php
<?php
include("config.php");
$id = (int)$_REQUEST['id'];
$image = "SELECT * FROM images WHERE ID = $id";
$image = mysql_query($image) or die('Error, query failed');
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;
?>
add_image.php
<?php
session_start();
$title = $_POST[title];
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) {
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()) {
$fileName = addslashes($fileName);
}
include("config.php");
$query = "INSERT INTO images (TITLE,IMAGE) VALUES ('$title','$content')";
mysql_query($query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
}
?>
sql注入檢測 – 2012-03-10 21:42:23
在你的查詢中有''''''。 – animuson 2012-03-10 21:43:22
爲什麼你將圖像存儲在數據庫中? – pomeh 2012-03-10 21:43:27