基礎測試:
<?php
header('Content-type: image/jpeg');
echo file_get_contents("1.jpg");
?>
寫入:
<?php
$conn=mysql_connect("127.0.0.1","root","");
if(!$conn)
{
echo "die.".mysql_error();
die();
}
//echo "succ";
mysql_select_db("test", $conn);
$ini=file_get_contents("1.jpg");
$ini=base64_encode($ini);//進行編碼 (可選)
if(mysql_query("insert into img values('$ini')"))echo "suc";?>
讀取:
<?php
error_reporting(0);//這句加上 不然有了warning的話出不來圖片
$conn=mysql_connect("127.0.0.1","root","");
if(!$conn)
{
echo "die.".mysql_error();
die();
}
mysql_select_db("test", $conn);
if($result=mysql_query("select * from img"))
while($row = mysql_fetch_array($result))
{
header('Content-type: image/jpeg');
echo base64_decode($row[jpg]);
}
?>
字段用的是vachar型 長度100000 ,有效防止上傳漏洞的出現