php 将图片以二进制存入mysql数据库,该如何解决

WBOY
Release: 2016-06-13 13:34:42
Original
1121 people have browsed it

php 将图片以二进制存入mysql数据库
有部分图片要存入mysql数据库,改怎么做啊?


$DBserver = "localhost";
$DBname = "new";
$DBuser = "root";
$DBpassword = "";

$con = mysql_connect("localhost","root","");

...

?>

------解决方案--------------------

PHP code


/*
 * 把图片存入mysql数据库
 *
 #
 # 数据表的结构 `images`
 #

CREATE TABLE images (
  picid int(3) NOT NULL auto_increment,
  picdata longblob NOT NULL,
  pictext varchar(100) NOT NULL default '',
  PRIMARY KEY  (picid)
) TYPE=MyISAM;

 */
if(trim($picfile[0])!=""){
    $link=@mysql_connect("localhost","root","root");
    //连接,用你的具体连接名替换root,具体连接密码替换root
        if($link==false) 
           {
     echo "<script>alert('连接数据库时发生错误,请稍后再试!')</script>";
           }
    $res=mysql_select_db("kkk");
        if($res==false) 
           {
     echo "<script>alert('打开数据库时发生错误,请稍后再试!')</script>";
           }
  $tmpset=0;  
  // 存放成功加入的图片数目
  for($i=0;$ialert('图片 ".$i." 提交失败!')";
                   continue;
                   }  
         $tmpset=$tmpset+1;                                 
         }
       }
  echo "<script>alert('操作成功!实际入库图片数 ".$tmpset." 张')</script>";
}
?>


<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!