#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    1
    Rep Power
    0
    Does any know where I can get an image
    into a blob type column from a perl dbi script?
    tried the following substitutions with no success.

    $var=~s/'/'/g;
    $var=~s///g;
    $var is where the image is located the
    insert always barfs
    any suggestions how to get it in?

    Thanks in advance,

    Rick
    rick@erealestateforyou.com
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Germany
    Posts
    1
    Rep Power
    0
    [QUOTE]Originally posted by dis:
    [B]Does any know where I can get an image
    into a blob type column from a perl dbi script?
    tried the following substitutions with no success.

    $var=~s/'/'/g;
    $var=~s///g;
    $var is where the image is located the
    insert always barfs
    any suggestions how to get it in?

    Thanks in advance,

    Rick
    rick@erealestateforyou.com


    Here is my way to solve this problem, by using an filehandler $ICONFILE

    my $icon;
    my $filesize;
    if ($ICONFILE ne '') {
    $filesize = -s $ICONFILE;
    my $in = read($ICONFILE, $icon, $filesize,0);
    if ($in != $filesize) {
    error("Error reading the file $ICONFILE");
    }

    $icon =~ s///g; # first do this
    $icon =~ s/00//g; # change NUL
    $icon =~ s/'/'/g;
    $icon =~ s/"/"/g;
    }

    Now you can use $icon within the sql-statement like:
    $sql = qq{INSERT INTO images VALUES ("$id", "$mimetype","$icon")};

    To get the image out of the database i wrote this perl-script:


    #!/usr/bin/perl -w

    use strict;
    use DBI;
    use CGI qw/:standard/;
    require "database.sub";
    # in database.sub there are the functions to connect (Connact_DB), run sql-statements (Do_SQL) and to disconnect the database.

    my $user = 'test';
    my $passwd ='none';
    my $id = param('id');

    &Connect_DB($user,$passwd);

    my $sql = "SELECT icon,mimetype FROM artikel WHERE id = $id";
    my $sth = &Do_SQL($sql);
    my $file = $sth->fetchrow_hashref;
    my $icon = $file->{'icon'};
    my $mimetype = $file->{'mimetype'};
    $sth->finish;
    &Disconnect;

    print header('$mimetype');
    print $icon;

    exit(0);
    #end


    I'll hope it will help you.


    Sauli

Similar Threads

  1. Perl script converting GIF and JPG images to BMP ???
    By Deanna475 in forum Perl Programming
    Replies: 20
    Last Post: February 17th, 2004, 07:35 PM
  2. PHP and MYSQL to display images
    By foreverdita in forum PHP Development
    Replies: 2
    Last Post: January 23rd, 2004, 09:21 AM
  3. SLOW Perl / MySQL execution times
    By Chireru in forum MySQL Help
    Replies: 9
    Last Post: January 2nd, 2004, 02:00 AM
  4. Perl / MySQL
    By cparker in forum Perl Programming
    Replies: 3
    Last Post: December 22nd, 2003, 02:31 PM
  5. images into mysql via phpmyadmin
    By kidswap in forum Beginner Programming
    Replies: 4
    Last Post: November 21st, 2003, 02:07 PM

IMN logo majestic logo threadwatch logo seochat tools logo