我可以使用以下代码将上传的图像存储在一个文件夹中(按其类别命名)及其相关数据,例如上载者信息,其类别在mysql中。

use strict;
use warnings;
use DBI;
use DBD::mysql;
use CGI;
$query = new CGI;
$uploader_name = $query->param("name");
$filename = $query->param("file");
$category = $query->param("cat");
$uploaded_dir = $category;
print $query->header();
$filename =~ s/.*[\/\\](.*)/$1/;
$filename =~ s/ /_/g;
$upload_filehandle = $query->upload("file");
$directory_filename = "$upload_dir/$filename";

# upload the file to the server

open UPLOADFILE, ">$directory_filename";
binmode UPLOADFILE;

while ( <$upload_filehandle> )
  {
   print UPLOADFILE;
  }

close UPLOADFILE;

# Open the file
# open MYFILE, $directory_filename || print "Cannot open file";
# my $blob_file;

# Read in the contents
# while (<MYFILE>)
#  {
#   $blob_file .= $_;
#  }
# close MYFILE;

# make the database connection
my $dbh=DBI->connect("DBI:mysql:database=pics;host=localhost","?","?");
# set the value of your SQL query
$query = "insert into pic(uploader_name, category) values (?, ?) ";

$sth = $dbh->prepare($query);
$sth->execute($uploader_name, $category) || print "Can't access database";

$sth->finish;
$dbh->disconnect;


我需要其余的元数据,例如其颜色,已加载图像的标题等,该怎么办?我听说过用于Java的元数据提取器。它们如何工作。建议最好的。
此外,如何将图像与其相应的元数据相关联以进行检索?

最佳答案

只需将“文件名”设置为数据库表中的一列,然后您就可以按文件名查找其余数据。

10-07 12:07
查看更多