php实现将文件写入数据库、从数据库读取文件(防止图片上传漏洞

基础测试:

<?phpheader('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";?>读取:

<?phperror_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 ,有效防止上传漏洞的出现

,你在潮湿的风中感受到了平稳的呼吸,多好听啊,

php实现将文件写入数据库、从数据库读取文件(防止图片上传漏洞

相关文章:

你感兴趣的文章:

标签云: