基础测试:
<?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 ,有效防止上传漏洞的出现