下面只告訴你如何實現圖片保存到數據庫,但在實際應用中並不推薦此種方法.
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 ;