Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can't use an undefined value as a HASH reference at uploadsingle.cgi line 44.

Reply
Thread Tools

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

 
 
jiles@jasnetworks.net
Guest
Posts: n/a
 
      02-26-2006
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;
}

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      02-26-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:(E-Mail Removed) ups.com:

> 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:mysqlxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" , "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...E_UPLOAD_FIELD

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

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      02-26-2006
(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Can't use an undefined value as an ARRAY reference at search.cgi line 139. JimJx Perl Misc 6 09-12-2007 04:10 PM
Can't use an undefined value as an ARRAY reference at C:/Perl/site/lib/Net/SFTP/ yogita281@gmail.com Perl Misc 0 11-21-2006 05:40 AM
hash key to var name of value hash key value Une bévue Ruby 5 08-10-2006 04:05 PM
Can't use undefined value as a HASH reference alexbarham@yahoo.ca Perl Misc 4 11-30-2005 05:44 PM



Advertisments