我知道你們中的一些人會說,這不是正確的方式,但即時通訊在完成一個應用程序的緊迫期限,截至目前我不能回去修改代碼來存儲目錄中的圖像。正確的方式上傳圖像到數據庫
現在這就是清除
的問題,我有我是通過鍵入此插入圖像到數據庫中。
(不介意類安全通話,所有正在做的是一些檢查的數據是有效的)
$filename = $security->secure($_FILES['imgschool']['name']);
$tmpname = $security->secure($_FILES['imgschool']['tmp_name']);
$imgsize = $security->secure($_FILES['imgschool']['size']);
$imgtype = $security->secure($_FILES['imgschool']['type']);
$school = $security->secure($_POST['school']);
//begin upload
if($imgsize > 0) {
$handle = fopen($tmpname, "r");
$content = fread($handle, filesize($tmpname));
$content = addslashes($content);
//code to add all this to database
}
變量$內容是圖像和所有得到的是和addslashes。我記得有人曾經提到過用base64做這件事,但我幾乎不記得它是如何寫成的。
這是怎麼了我從數據庫中的所有查詢調用圖像
一邊和諸如此類的東西 這是調用圖像
header("Content-length: ".$imgsize);
header("Content-type: ".$imgtype);
header("Content-Disposition: attachment; filename=".$imgname);
print $row['img'];
我遇到的問題是主要部分而不是圖像顯示。鏈接僅示出,所以在這種情況下,我只看到這個
http://localhost/admin/school-catalog.php?page=gallery&id=4
打開該網頁時與在URL中設置了正確的PARAMS查看圖像。
對於那些希望看到正在做保存圖像等 我複製了整段
//save image to db
if(isset($_POST['btnupload'])) {
$filename = $security->secure($_FILES['imgschool']['name']);
$tmpname = $security->secure($_FILES['imgschool']['tmp_name']);
$imgsize = $security->secure($_FILES['imgschool']['size']);
$imgtype = $security->secure($_FILES['imgschool']['type']);
$school = $security->secure($_POST['school']);
//begin upload
if($imgsize > 0) {
$handle = fopen($tmpname, "r");
$content = fread($handle, filesize($tmpname));
$content = base64_encode($content);
}
$save = mysql_query("insert into tbl_schoolgallery(id,hash,img,imgtype,imgsize) values(null,'$school','$content','$imgtype','$imgsize')") or die(mysql_error());
header("Location: school-catalog.php?page=school_gallery");
}
//call image from db
$query = mysql_query("select * from $tbl where id = '$id'") or die(mysql_error());
while($row = mysql_fetch_assoc($query)) {
$imgtypeget = explode("/", $row['imgtype']);
$imgname = "img.".$imgtypeget[1];
$imgtype = $row['imgtype'];
$imgsize = $row['imgsize'];
header("Content-length: ".$imgsize);
header("Content-type: ".$imgtype);
print base64_decode($row['img']);
print $row['img'];
}
您不應該使用print $內容嗎? – 2009-06-26 05:49:59
我不能因爲即時通訊從數據庫中調用圖像 – SarmenHB 2009-06-26 05:51:45