用addslashes有时会有问题的,建议采用base64$filename = "test.jpg";
// 读取文件
$fp = fopen($filename,"rb");
$picture = fread($fp,filesize($filename));
$picture = base64_encode($picture);
fclose($fp);
// 操作MYSQL
$conn=mysql_connect("localhost","root","");
@mysql_select_db("test",$conn);
// 存入数据库
$query="insert into pic (filename,picture) values ('$filename','$picture')";
$result=mysql_query($query);
$id=mysql_insert_id();
// 读取数据
$query="select * from pic where id='$id'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$data = base64_decode($row[picture]);
// 显示文件
header("Content-type: image/jpeg");
echo $data;

解决方案 »

  1.   

    去這里找一下,我收集過這种文章. 也試過. 在查詢那里輸入MYSQL就可以了. 
    http://starho.51.net
      

  2.   

    我一直用base64_encode()来完成这个工作
    如果你要用addslashes()的话也要用stripslashes()在输出的时候un-quote
    相当于base64_decode().
    不过他们的速度我没有作过测试,  :-( 
    楼主有兴趣可以做一下啊^-^
      

  3.   

    不能取出来,在这一行报错:header("Content-type: image/jpeg");