如何使用perl把图片存储到数据库中

如何使用perl把图片存储到数据库中

如何把图片文件转换成二进制存入数据库
用一个变量储存那张图档内容..
然後用
$sql = "insert into table  (picture) values (?)";
$sth->execute("$picture");
要注意的是
picture的type要是Blob之类的type
open FILE,"<$filename";
my $pic = <FILE>;
close FILE;
#在Tk中
$widget->Photo(-data=>$pic,-format=>'gif');

尝试了一下,好像不行
请开启binmode
read $buf, $f, -s $filename
thx, 追加问一下,如何开启啊?
binmode(FILE);
代码如下, 测试失败

#!/usr/bin/perl

use Tk;

my $mw = MainWindow->new();

my $file = "D:\\xxx\\xxx.gif";

my $x;
open FILE,"<$file";
binmode FILE;
$x = <FILE>;
close FILE;

my $pic = $mw->Photo(-data=>$x);

$mw->Label(-image=>$pic)->pack;

MainLoop;

错误信息如下:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.



QUOTE:
原帖由 redwyz 于 2008-1-28 18:57 发表
代码如下, 测试失败

#!/usr/bin/perl

use Tk;

my $mw = MainWindow->new();

my $file = "D:\\xxx\\xxx.gif";

my $x;
open FILE,"

你也可以用楼上提到的用read..或再多加一行 $/ = '';
测试过..okay...ab.JPG与abc.jpg一样大...

[Copy to clipboard] [ - ]
CODE:
open(FF,"/www/pams-www/images/ab.JPG");
binmode(FF);
$/ = '';   #---注意这里.....要把换行字符换成空的..因为<>是以  $/ 为一行的判断依据..
$abc = <FF>;
close(FF);
open(GG,">abc.jpg");
print GG $abc;
close(GG);