Can't use an undefined value as a HASH reference at uploadsingle.cgi line 44.

Discussion in 'Perl Misc' started by jiles@jasnetworks.net, Feb 26, 2006.

  1. Guest

    I get this error "Can't use an undefined value as a HASH reference at
    uploadsingle.cgi line 44." when i run this script on the web server. i
    can't figure out why, any help would be great. the whole script is
    below.


    #!/usr/bin/perl -Tw
    # uploadsigle.cgi

    use strict;
    use DBI;
    use File::Basename;
    use CGI qw:)standard);
    use CGI::Carp qw(fatalsToBrowser);

    my $Directory =
    "/hsphere/local/home/jilesfre/jilesfamily.net/cgi-bin/pictures";
    my $Url_Path = "cgi-bin/pictures";
    my $File_Name = param('filename');
    my $Description = param('description');
    my $File = Get_File_Name($File_Name);


    Store_Results();
    Store_Description();
    Print_Results();
    sub Store_Description{
    my $DBH = DBI->connect(
    "DBI:mysql:jilesfr_pictures:69.6.255.192:3306", "jilesfr_pictures",
    "upload" ) or die "Error: $DBI::errstr\n";
    my $sth_insert =
    $DBH->prepare( qq{INSERT INTO files (Description,
    FileName) VALUES (?,?)} )
    or die $DBH->errstr;
    $sth_insert->execute($Description, $File);
    $DBH->disconnect;
    }

    sub Get_File_Name{
    if( $ENV{HTTP_USER_AGENT} =~ /win/i ){
    fileparse_set_fstype("MSDOS");
    }
    elsif( $ENV{HTTP_USER_AGENT} =~ /mac/i ){
    fileparse_set_fstype("MacOS");
    }
    my $full_name = shift;
    $full_name = basename($full_name);
    $full_name =~ s!\s!\_!g;
    return($full_name);
    }

    sub Store_Results{
    my $data;
    my $mime = uploadInfo($File_Name)->{'Content-Type'};
    open (STORAGE, ">$Directory/$File")
    or die "Error: $Directory/$File: $!\n";
    if($mime !~ /text/){
    binmode (File_Name);
    binmode (STORAGE);
    }
    while( read($File_Name, $data, 1024) ){
    print STORAGE $data;
    }
    close STORAGE;
    }

    sub Print_Results{
    my $link = "$Url_Path/$File";
    print header;
    print start_html("Example 3");
    print qq(<pre>);
    print qq(<b>File Sent:</b> $File_Name);
    print qq(<b>File Name:</b> $File);
    print qq(<b>Link to File:</b><a href="$link">$link</a>);
    print qq(</pre>);

    print end_html;
    }
    , Feb 26, 2006
    #1
    1. Advertising

  2. wrote in news::

    > I get this error "Can't use an undefined value as a HASH reference at
    > uploadsingle.cgi line 44." when i run this script on the web server.
    > i can't figure out why,


    Ask Perl to help you before you ask thousands of other people:

    D:\Home\asu1\UseNet\clpmisc\gif> perl -cT t.pl
    [Sat Feb 25 21:44:55 2006] t.pl: Name "main::File_Name" used only once:
    possible typo at t.pl line 52.
    t.pl syntax OK

    ....

    > sub Store_Description{
    > my $DBH = DBI->connect(
    > "DBI:mysql:xxxxxxxxxxxxxxxx:xxxxxxxxxxxx:xxxx", "xxxxxxxxxxxxxxxx",


    Especially if you are going to end up posting your user id and
    password for the whole world to see.

    See http://search.cpan.org/~lds/CGI.pm-3.17/CGI.pm#CREATING_A_FILE_UPLOAD_FIELD

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Feb 26, 2006
    #2
    1. Advertising

  3. Re: Can't use an undefined value as a HASH reference at uploadsingle.cgiline 44.

    wrote:
    > I get this error "Can't use an undefined value as a HASH reference at
    > uploadsingle.cgi line 44." when i run this script on the web server. i
    > can't figure out why, any help would be great. the whole script is
    > below.


    I'd take an easier route. Instead of this code:

    > use File::Basename;
    > use CGI qw:)standard);
    >
    > my $Directory =
    > "/hsphere/local/home/jilesfre/jilesfamily.net/cgi-bin/pictures";
    > my $Url_Path = "cgi-bin/pictures";
    > my $File_Name = param('filename');
    > my $Description = param('description');
    > my $File = Get_File_Name($File_Name);
    >
    > Store_Results();
    > Print_Results();
    >
    > sub Get_File_Name{
    > if( $ENV{HTTP_USER_AGENT} =~ /win/i ){
    > fileparse_set_fstype("MSDOS");
    > }
    > elsif( $ENV{HTTP_USER_AGENT} =~ /mac/i ){
    > fileparse_set_fstype("MacOS");
    > }
    > my $full_name = shift;
    > $full_name = basename($full_name);
    > $full_name =~ s!\s!\_!g;
    > return($full_name);
    > }
    >
    > sub Store_Results{
    > my $data;
    > my $mime = uploadInfo($File_Name)->{'Content-Type'};
    > open (STORAGE, ">$Directory/$File")
    > or die "Error: $Directory/$File: $!\n";
    > if($mime !~ /text/){
    > binmode (File_Name);
    > binmode (STORAGE);
    > }
    > while( read($File_Name, $data, 1024) ){
    > print STORAGE $data;
    > }
    > close STORAGE;
    > }


    you can do:

    use CGI::UploadEasy;
    use CGI qw:)standard);

    my $Directory =
    "/hsphere/local/home/jilesfre/jilesfamily.net/cgi-bin/pictures";

    my $ue = CGI::UploadEasy->new(-uploaddir => $Directory);

    my $Url_Path = "cgi-bin/pictures";
    my $File_Name = param('filename');
    my $Description = param('description');
    my $File = ( keys %{ $ue->fileinfo } )[0];

    Print_Results();

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 26, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    499
    red floyd
    Nov 10, 2011
  2. Replies:
    14
    Views:
    231
    Tomi Häsä
    Jan 10, 2005
  3. Replies:
    4
    Views:
    239
  4. Replies:
    0
    Views:
    129
  5. JimJx
    Replies:
    6
    Views:
    876
    John W. Krahn
    Sep 12, 2007
Loading...

Share This Page