我想把一个图片,插入到数据库表中,表中对应的图片字段为BLOB型.
代码 <?php
   //$picture="e:\\pic\\4.txt";  $picture="e:\\pic\\9.jpg";
   echo "$picture";
   $psize=filesize($picture);
   echo "$psize";
   $mysqlpicture=addslashes(fread(fopen($picture,"r"),$psize));
   echo "$mysqlpicture";
   unlink($picture);
   $host="localhost";
   $user="root";
   $password="123456";
   $database="teacher";
   $table_name="student";
   $conn=mysql_connect($host,$user,$password);
   if(!mysql_connect($host,$user,$password))
      die("connect erroring..... ".mysql_error());  
    mysql_select_db($database,$conn);
    mysql_query("SET NAMES 'GB2312'");
   mysql_query("insert into student (pic) values ('$mysqlpicture')") or die("cant't perform insert");?>
此代码能实现文本文件的插入到数据库中,却不能实现小的图片插入到数据当中,
异常:
Warning: filesize() [function.filesize]: stat failed for e:\pic\9.jpg in D:\AppServ\www\b.php on line 6
图片大小为5KB.请高手指点.

解决方案 »

  1.   

    你先用is_file()判断下
    $picture="e:\\pic\\9.jpg";
    var_dump(is_file($picture));
      

  2.   

    你有 unlink($picture);
    所以只要程序被执行,图片就被删除了。再执行就要出错了
      

  3.   

    $PSize = filesize($Picture); 
       $mysqlPicture = addslashes(fread(fopen($Picture, "r"), $PSize)); 
       mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
       @mysql_select_db($db) or die("Unable to select database"); 
       mysql_query("INSERT INTO Images (Image) VALUES ($mysqlPicture)") or die("Cant Perform Query"); 
      

  4.   

    mysql_query("SET NAMES 'GB2312'");最好删除。
    或改成mysql_query("SET NAMES 'utf8'");