Angharad has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get a cgi script working but it's unable to find a file it requires.

The cgi script is located in my /public_html/cgi-bin (of course) and my file in a directory called /public_html/uploadedfiles

I don't understand why my script is not finding the file ... it is certainly there and at that location.

Code follows

#!/usr/bin/perl -wT # # # # ensure all fatals go to browser during debugging and set-up # comment this BEGIN block out on production code for security BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } use strict; use warnings; use diagnostics; use CGI qw/:standard/; #print "Content-type: text/html\n\n" # # Upload directory for files # my $upload_dir = "/home/me/uploaded_files"; my $file = "file.txt"; # # Path to PDB processing program # my $program = "/home/me/programs/program"; # # Get the name of the file to process from the command line # Later we will get this from the input to the CGI program # #my $input_file = shift; my $input_file = "$file"; #die "Usage: $0 INPUT_FILENAME\n" unless $input_file; #die "Can't process '$upload_dir/$input_file': File does not exist!\n" # unless -f "$upload_dir/$input_file"; # # Create web page... # print start_html("Processing PDB file '$input_file' ..."), $/, h1("Processing PDB file '$input_file' ..."), $/; chdir $upload_dir; die "Usage: $0 INPUT_FILENAME\n" unless $input_file; die "Can't process '$upload_dir/$input_file': File does not exist!\n" unless -f "$upload_dir/$input_file"; open (PROG, "| $program") || die "Can't run '$program': $!\n"; print PROG "$input_file\n"; close(PROG); print p("OK .. working thus far"), end_html();
Any help much appreciated

Replies are listed 'Best First'.
Re: where art thou file?
by liverpole (Monsignor) on Feb 28, 2006 at 12:11 UTC
        ... my file in a directory called /public_html/uploadedfiles

    Are you sure that's where your file is supposed to be?  According to your code:

    # # Upload directory for files # my $upload_dir = "/home/me/uploaded_files"; # ... chdir $upload_dir; die "Usage: $0 INPUT_FILENAME\n" unless $input_file; die "Can't process '$upload_dir/$input_file': File does not exist!\n" unless -f "$upload_dir/$input_file";
    So I'm not seeing any place where you reference /public_html/uploadfiles (or even just uploadfiles) in your program.

    Maybe you have a symbolic link from /home/me to /public_html, and you meant uploadedfiles (without the underscore) in the program?

    And what do the logs say?  Try running tail -100f /var/log/httpd/error_log in a separate window before you run it, for extra information.


    @ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
      hi, thanks for your reply.
      /home/me etc refers to the local directory system on the server. I'm utterly confused by the public_html concept to be honest, because apaprently you are not supposed to include that in your path.
      On my server ... it says /public_html/uploadedfiles. I *think* that corresponds to /home/me/uploadedfiles for some reason. If anyone could explain why tat is to me, I would appreciate that also :)
      The log files say that the file isn't found by the way.

        Generally speaking (i.e. in every case I've encountered) /home/USERNAME/public_html corresponds to either http://www.example.com/~USERNAME/ or http://USERNAME.example.com/.

        Thus you should not include "public_html" in your URL path. It is still a real directory on the filesystem so it should appear when referencing the filesystem path.

        Inside the Perl script it is a filesystem path, but outside the Perl script (i.e. in any HTML your script outputs) then it is a URL path.

        Hi again,

        Try looking at the configuration file for httpd.  It's someplace like /etc/httpd/conf/httpd.conf  I am by no means an expert at html/cgi (although I'm trying to learn!), but I know that httpd.conf is where things like Apache pathname configuration are handled.  Basically, you can define which directory will be the starting point for a given URL pointing to your server.  Note that the starting point may differ depending on whether you're executing a script (CGI) or simply fetching a file.  So if you have /public_html configured as the "starting point", an URL which references your server will access files relative to the /public_html directory.

        You may also want to read some of the Apache/http documention (try a Google for "configuring html", or something similar).  Good luck!


        @ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
Re: where art thou file?
by idle (Friar) on Feb 28, 2006 at 12:27 UTC
    And what the error say? Can't find which one file?
      The one that is assigned to the variable file near the top of the script. It's located in the uploadedfiles directory