我正在尝试在数据库中插入图像。该数据库有一个名为的字段images
,其类型为 BLOB。我正在尝试插入图像,但只存储了前 2.2KB。即使我插入另一个图像,它也只在数据库中存储 2.2KB。
当我尝试在我的应用程序中显示此图像时,它没有显示;它只是一个小图标,而不是图像。如何以正确的方式插入图像?
use CGI;
my $file = $q->param("file");
$file = 'C:/wamp/bin/apache/apache2.2.22/cgi-bin/images/2.jpg';
open(my $fh, $file);
my $data;
binmode($fh);
read($fh, $data, (stat($fh))[7]);
close($fh);
my $Data = {
table =>'student',
data => {
Image => $fh,
}
};
Data::Insert($Data);
print $q->header;
print $q->start_html(
-title => "student",
);
print $q->end_html;
显示图像.pl
my $q = new CGI();
my $handle = Dbm::connection();
$id = $q->param('id_person');
$getimage = $handle->selectrow_array (<<SQLEOF);
SELECT Image
FROM student
WHERE ID = '$id'
SQLEOF
print "Content-Type: image/jpeg\n";
print "Content-length: \n\n";
binmode STDOUT;
print STDOUT $getimage;