Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

5 views
Skip to first unread message

ji...@jasnetworks.net

unread,
Feb 25, 2006, 9:41:51 PM2/25/06
to
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;
}

A. Sinan Unur

unread,
Feb 25, 2006, 9:52:27 PM2/25/06
to

> 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 <1u...@llenroc.ude.invalid>
(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

Gunnar Hjalmarsson

unread,
Feb 26, 2006, 7:00:54 AM2/26/06
to
ji...@jasnetworks.net 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

0 new messages