Perl File Uploading - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Perl File Uploading

ocYrusocYrus Posts: 15Member
[b][red]This message was edited by the ocYrus at 2002-4-5 15:17:20[/red][/b][hr]
Can't use an undefined value as a HASH reference at /usr/local/www/cgi-bin/upload1.cgi line 38.


Thats the error

Heres the code..
#!/usr/bin/perl -Tw
use DBI;
use File::Basename;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
my $Directory = "/usr/local/www/programming/upload";
my $Url_Path = "/programming/upload";
my $File_name = param('filename');
my $Description = param('description');
my $File = Get_File_Name($File_Name);
$CGI::POST_MAX = 1024 * 716800;
Store_Results();
Store_Description();
Print_Results();
sub Store_Description{
my $DBH = DBI->connect("DBI:mysql", "monty", "***");
my $sth_insert =
$DBH->prepare( qq{INSERT INTO files (Description, FileName)
VALUES (?,?)} )
or die $DBI->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: $!
";
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('File Upload Example 3');
print<<HTML;
<PRE>
File Sent: $File_Name
File Name: $File
Link to File: View Files

HTML
print end_html;
}


-ocYrus
www.ocyland.com
www.imagine-wedesigns.com
www.lightx-security.com


Comments

  • slicer69slicer69 Posts: 272Member
    I'm not a Perl expert, but I think I foudn the problem.
    Near the top of your code, you define a variable called
    "$File_name"

    On line 38 you use a varibale called
    "$File_Name"

    I think that since Perl is case senstive, this will cause a problem.

  • heeroyuyheeroyuy Posts: 125Member
    : I'm not a Perl expert, but I think I foudn the problem.
    : Near the top of your code, you define a variable called
    : "$File_name"
    :
    : On line 38 you use a varibale called
    : "$File_Name"
    :
    : I think that since Perl is case senstive, this will cause a problem.
    :
    :
    I beg to differ. As I recall, perl isn't case sensitive. I'd check this just to be safe, but as I recall it isn't.

    later,
    Travis
  • ocYrusocYrus Posts: 15Member
    : : I'm not a Perl expert, but I think I foudn the problem.
    : : Near the top of your code, you define a variable called
    : : "$File_name"
    : :
    : : On line 38 you use a varibale called
    : : "$File_Name"
    : :
    : : I think that since Perl is case senstive, this will cause a problem.
    : :
    : :
    : I beg to differ. As I recall, perl isn't case sensitive. I'd check this just to be safe, but as I recall it isn't.
    :
    : later,
    : Travis
    :

    Actually it is case sensitive, i remember reading this is Perl Little Black book

Sign In or Register to comment.