"Randy A. Katz" wrote:
>
> Hello,
>
> Sorry if this question is ignorant, however: Can I store binary data into a
> BLOB type? Can I store a graphic file like a jpg/gif into a BLOB? Can I
> store sound clips, video, and how is this accomplished?
>
> Thank you,
> Randy Katz
>
Yes, BLOB is the type to store stuff like that in, and all you need to
do is to escape all the weird characters.
However, there is an argument ( and I tend to support it), that storing
large chuncks of binary data should be done by a filesystem location
reference. Here is an example of a setup you can use for a prototype:
Let's say we have a phone directory with pictures, for each person we
know their name, phone number and have a JPEG picture. Here is what we
can do:
create table person (id int auto_increment primary key, name char(20),
phone char(7));
Then we mkdir /home/httpd/html/phonedir/images
Since there is a lot of people in our directory, we hash them on the
last two digits of their id, and create the following subdirectories
(the code speaks for itself):
$root_dir = "/home/httpd/html/phonedir/images";
foreach $i (0..9)
{
foreach $j (0..9)
{
mkdir("$root_dir/$i/$j", 0644);
}
}
Then for each person you store their image according to the following
algorithm ( we assume $id to contain person's id, and $image_file to
contain the location of the image):
$image_hash1 = $id % 10;
$image_hash2 = int($id / 10) % 10;
$image_dest = "$root_dir/$image_hash1/$image_hash2/${id}.jpg";
system("mv $image_file $image_dest") && die "mv failed: $!\n";
# and, not or, because 0 means success, non-0 failure
Note that the above is just part of the set-up, not your actual code in
the web application. Now we go to your web application. You run a query,
and among other things store the value of a person's id in a Perl
variable $id. Then
$image_root = "/phonedir/images" ; # this assumes your DOCUMENT_ROOT to
be /home/httpd/html/
$image_hash1 = $id % 10;
$image_hash2 = int($id / 10) % 10;
$image_http_ref = "$image_root/$image_hash1/$image_hash2/${id}.jpg";
print <<EOT;
Look at this guy: <img src=$image_http_ref>
EOT
Hope this gives you an idea.
--
Sasha Pachev
http://www.sashanet.com/ (home)
http://www.direct1.com/ (work)