我在從數據庫中檢索圖像時遇到問題。下面是上傳圖像到數據庫的代碼:使用mysql在php中檢索並上傳圖像
<form method="post" action="index2.php" enctype="multipart/form-data">
<input type="file" name="drimg2"/>
<input type="submit" name="submit2" value="Save"/>
</form>
<?php
if(isset($_POST['submit2'])) {
$con=mysql_connect("localhost","root","root");
mysql_select_db("test",$con);
$imgname1=$_FILES['drimg2']['name'];
echo $imgname1;
$imageextension1 = substr(strrchr($imgname1,'.'), 1);
if (($imageextension1!= "jpg") && ($imageextension1 != "jpeg") && ($imageextension1 != "gif")&& ($imageextension1 != "png")&& ($imageextension1 != "bmp")) {
die('Unknown extension. Only jpg, jpeg, and gif files are allowed. Please hit the back button on your browser and try again.');
}
if (($imageextension1= "jpg") && ($imageextension1= "jpeg") && ($imageextension1= "gif") && ($imageextension1 = "png") && ($imageextension1 = "bmp")) {
$query1=mysql_query("INSERT INTO store set image='$imgname1'");
$action = move_uploaded_file($_FILES['drimg2']['tmp_name'],"images/".$imgname1);
die('not Uploded');
}
}
?>
現在我想檢索數據庫中的所有圖像;爲了這個,我現在用的是下面的代碼:
<?php
$query1="select * from store";
$fetch=mysql_query($query1);
while ($rows=mysql_fetch_array($fetch)) {
echo "<img src='images/".$rows['image']."' />";
}
?>
TBH你不能上傳圖像只有'「;}?>' – EaterOfCode 2012-08-08 07:49:58
檢查我的代碼user2727841 – user2727841 2014-01-01 06:53:28