首页 > php开发 > PHP将图片存入mysql实现代码

PHP将图片存入mysql实现代码

下面只告诉你如何实现图片保存到数据库,但在实际应用中并不推荐此种方法.

PHP实例代码如下:

mysql_connect('localhost','root','root'); 
mysql_select_db('ac'); 
$picdir ="/a/ag.gif"; 
$image = addslashes(file_get_contents($picdir)); 
$sql ="insert into tbl_name (field) values ('" . $image . "')"; 
mysql_query($sql);

数据库表的结构 `test`,代码如下:

create table if not exists `test` ( 
  `id` int(8) not null auto_increment, 
  `title` char(150) default null, 
  `content` longblob, 
  `addnewcolumn` varchar(20) not null, 
  primary key  (`id`) 
) engine=myisam default charset=utf8 auto_increment=1 ;

   


永久链接:http://www.phprm.com/develop/fs5368.html

转载随意!带上文章地址吧。

标签:php图片存入mysql 存入mysql

发表留言