- 论坛徽章:
- 0
|
如何使用perl将图片存入mysql中?
这段程序你看看吧
- foreach (keys %{ $self->;{'_attachment'} }) {
- unless ($self->;{'_attachment'}->;{$_}) {
- my $sth = $dbh->;prepare('INSERT INTO attachment (file_name,file_content) VALUES (?,?)');
- my $file_name = File::Basename::basename($_);
- my $file_content;
- open FH, $_ or croak("Can't open file $_.");
- {
- local $/ = undef;
- binmode FH;
- $file_content = <FH>;;
- }
- close FH;
- $sth->;execute($file_name, $file_content) or croak("Can't insert attachment $file_name: $DBI::errstr");
- $self->;{'_attachment'}->;{$_} = $self->;_get_last_insert_id;
- }
- }
复制代码
另外如果文件比较大的话还需要把max_allowed_packet设大一点。 |
|