Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

fileparse(): need a valid pathname

by roopra (Initiate)
on Jul 06, 2018 at 18:18 UTC ( #1218062=perlquestion: print w/replies, xml ) Need Help??
roopra has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Am trying to fix a bug in the Perl CGI code.

Below is the message

Status: 500 Content-type: text/html <h1>Software error:</h1> <pre>fileparse(): need a valid pathname at login.cgi line 34. </pre> <p> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. </p> [Fri Jul 6 21:02:17 2018] login.cgi: fileparse(): need a valid pathna +me at login.cgi line 34.

please help

#!/usr/bin/perl -w #use strict; use DBI; use Carp; use File::Path; use File::stat; use File::Basename; use Cwd; use CGI; use CGI::Carp qw(carpout fatalsToBrowser); use Digest::MD5 qw(md5_hex); #use lib "$ENV{'DOCUMENT_ROOT'}/home/honeyisl/public_html/cgi-bin/sche +dule"; use lib "/home/honeyisl/public_html/cgi-bin/schedule"; use SUBS; use DBDAT; no warnings 'uninitialized'; #use lib "$ENV{'DOCUMENT_ROOT'}/home/honeyisl/public_html/cgi-bin"; use lib "/home/honeyisl/public_html/cgi-bin"; use Date::Manip; use Apache::DBI (); use Mail::Mailer; use Exporter; # P A R A M S A N D V A R I A B L E S my $q = CGI->new; my $action=$q->param("submit") || 'Annonymous'; my $user=$q->param('user'); my $msg=$q->param('msg'); #-------------------------------------------------------------------- my $md5 = Digest::MD5->new; my $digest; my $dir=dirname($ENV{'SCRIPT_FILENAME'}); #my $dir=cwd(dirname($ENV{"SCRIPT_FILENAME"}));
The error is coming from line " my $dir=dirname($ENV{'SCRIPT_FILENAME'});" Please help Thanks in advance

Replies are listed 'Best First'.
Re: fileparse(): need a valid pathname
by haj (Pilgrim) on Jul 06, 2018 at 18:46 UTC

    I'd guess that your web server software doesn't provide the environment variable SCRIPT_FILENAME. That variable is not documented in the CGI 1.1 RFC, so maybe you need to check the documentation of your web server whether they changed their behaviour.

    Technically, $ENV{SCRIPT_FILENAME} is supposed to be the name of your program in "file space", as opposed to $ENV{SCRIPT_NAME} which is part of the RFC and is the name of the same program in "URL space". Depending on your web server configuration, you might succeed by simply writing my $dir=dirname($0); because $0 is the file name of your program.

Re: fileparse(): need a valid pathname
by hippo (Canon) on Jul 06, 2018 at 20:04 UTC
    use Apache::DBI ();

    Can you explain why you are using this module? Are you using some sort of persistent CGI? That certainly isn't what your prose suggests. Not that this directly impacts your error condition but it does make one wonder what else you might not be telling us.

Re: fileparse(): need a valid pathname
by eyepopslikeamosquito (Chancellor) on Jul 08, 2018 at 11:18 UTC

    #use strict;
    Can you explain why you commented out this line? Not that this directly impacts your error condition, but it may give us more context.

Re: fileparse(): need a valid pathname
by Anonymous Monk on Jul 06, 2018 at 19:32 UTC
Re: fileparse(): need a valid pathname
by ikegami (Pope) on Jul 09, 2018 at 03:10 UTC
    use lib "/home/honeyisl/public_html/cgi-bin/schedule"; ... my $dir = dirname($ENV{'SCRIPT_FILENAME'});
    should be
    use FindBin qw( $RealBin ); use lib $RealBin; ... my $dir = $RealBin;
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1218062]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2018-09-22 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (190 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!