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

J

jiles

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

A. Sinan Unur

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
 
G

Gunnar Hjalmarsson

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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top