Get_File_Name() Function. - Programmers Heaven

Howdy, Stranger!

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

Categories

Get_File_Name() Function.

ApotheosisApotheosis Posts: 15Member
[b][red]This message was edited by Apotheosis at 2003-7-8 20:36:22[/red][/b][hr]
Currently I'm trying to get this script going which is meant to upload files to my web server. Although, whenever I run the program, I get an internal server error. Here is the entire script, although I have located the problem down to line 12 (my $File = Get_File_Name($File_Name);)

[code]
#!/usr/bin/perl -Tw

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

my $Directory = "/home/MYUSERNAME/public_html/plworld/board/storage";
my $Url_Path = "/storage";
my $File_Name = param('filename');
my $Description = param('description');
my $File = Get_File_Name($File_Name);

$CGI::POST_MAX = 1024 * 250;


Store_Results();
Store_Description();
Print_Results();


sub Store_Description{
my $DBH = DBI->connect("DBI:mysql:info:localhost","MYUSERNAME","MYPASSWORD");

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: $!
";

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: $link
View Files

HTML

print end_html;
}
[/code]

Then the html file that sends the information:

[code]

[/code]

If anyone can locate the problem within my script, it would be appreciated.

Thanks.


Comments

  • JonathanJonathan Posts: 2,914Member
    : [b][red]This message was edited by Apotheosis at 2003-7-8 20:36:22[/red][/b][hr]
    : Currently I'm trying to get this script going which is meant to
    : upload files to my web server. Although, whenever I run the
    : program, I get an internal server error. Here is the entire script,
    : although I have located the problem down to line 12 (my $File =
    : Get_File_Name($File_Name);)
    :
    : ~snip~
    :
    : If anyone can locate the problem within my script, it would be
    : appreciated.

    Error I get it to throw is "Can't use an undefined value as a HASH reference at line 54.".

    uploadInfo($File_Name)->{'Content-Type'}

    That looks rather suspect to me, but I could be wrong.

    I also don't see the functions fileparse_set_fstype and basename anywhere, but they are probably default exports from the modules you're using. They aren't reporting an error either, so there's probably nothing in that. :-)

    Try running it at the command line and doing a perl -c on it to see what falls out.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • ApotheosisApotheosis Posts: 15Member
    : : [b][red]This message was edited by Apotheosis at 2003-7-8 20:36:22[/red][/b][hr]
    : : Currently I'm trying to get this script going which is meant to
    : : upload files to my web server. Although, whenever I run the
    : : program, I get an internal server error. Here is the entire script,
    : : although I have located the problem down to line 12 (my $File =
    : : Get_File_Name($File_Name);)
    : :
    : : ~snip~
    : :
    : : If anyone can locate the problem within my script, it would be
    : : appreciated.
    :
    : Error I get it to throw is "Can't use an undefined value as a HASH reference at line 54.".

    :
    : uploadInfo($File_Name)->{'Content-Type'}
    :
    : That looks rather suspect to me, but I could be wrong.
    :


    : I also don't see the functions fileparse_set_fstype and basename anywhere, but they are probably default exports from the modules you're using. They aren't reporting an error either, so there's probably nothing in that. :-)
    :
    : Try running it at the command line and doing a perl -c on it to see what falls out.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    I got the same error, "Can't use an undefined value as a HASH reference at line 54." so I changed "uploadInfo($File_Name)->{'Content-Type'}" to:

    [code]my $other = uploadInfo($File_Name);
    my $mime = $other->{'Content-Type'};[/code]

    Or something like that... And I didn't recieve that error anymore. But, after a little longer of playing around I altered the script quite a bit. Ended up changing it back to "uploadInfo($File_Name)->{'Content-Type'}", and it all worked out.

    Thank you for your help. :)

  • JonathanJonathan Posts: 2,914Member
    : I got the same error, "Can't use an undefined value as a HASH
    : reference at line 54." so I changed "uploadInfo($File_Name)->
    : {'Content-Type'}" to:
    :
    : [code]my $other = uploadInfo($File_Name);
    : my $mime = $other->{'Content-Type'};[/code]
    :
    : Or something like that... And I didn't recieve that error anymore.
    : But, after a little longer of playing around I altered the script
    : quite a bit. Ended up changing it back to "uploadInfo($File_Name)->
    : {'Content-Type'}", and it all worked out.
    Pleased you got it all worked out in the end. I don't tend to use constructs like that (function returning a reference, instantly dereferencing it with the infix operator), but now I look at it again there's nothing wrong with it really.

    : Thank you for your help. :)
    You're welcome. Thanks for having an interesting username, which I've just looked up at dictionary.com. :-)

    Later,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • ApotheosisApotheosis Posts: 15Member
    : : I got the same error, "Can't use an undefined value as a HASH
    : : reference at line 54." so I changed "uploadInfo($File_Name)->
    : : {'Content-Type'}" to:
    : :
    : : [code]my $other = uploadInfo($File_Name);
    : : my $mime = $other->{'Content-Type'};[/code]
    : :
    : : Or something like that... And I didn't recieve that error anymore.
    : : But, after a little longer of playing around I altered the script
    : : quite a bit. Ended up changing it back to "uploadInfo($File_Name)->
    : : {'Content-Type'}", and it all worked out.
    : Pleased you got it all worked out in the end. I don't tend to use constructs like that (function returning a reference, instantly dereferencing it with the infix operator), but now I look at it again there's nothing wrong with it really.
    :

    : : Thank you for your help. :)
    : You're welcome. Thanks for having an interesting username, which I've just looked up at dictionary.com. :-)
    :
    : Later,
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    I am also glad I got it working :). And, I'm glad you find my username interesting. :p

Sign In or Register to comment.