Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't open a file with CGI

Status
Not open for further replies.
Mar 11, 2004
127
GB
ok, I have a website that I'm trying to use as much CGI on as possible.

THe basic idea behind the page I'm having trouble with is that I have reports in a folder: /reports/file1.txt and so on. And I want to open the file and format it all via the CGI.

I am passing a parameter into the CGI script from the URL on the parent page. However, I'm getting an File does not exist error.

So to trouble shoot this I put the variable into an anchor href and when the page is generated, this link opens the file fine.

I really am pickled by this one. Can anyone help?

Thanks in advance,
Ant
 
Posting code helps.. but you are probably getting your web directories vs real directorys confused. ie if you file is your open command needs to have the real full path to file.txt like

open(FILE, "</path/to/apache/htdocs/reports/file.txt") or die "can't open file:$!\n";



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I did wonder about this. The relative path I'm using is fine on a link, but guess perl needs the full path instead.

I've not got the hosting details yet so guess I'll have to chase them up from the owner and then I'll be able to see what the full path really is.

THanks for your help!
Ant
 
You should always try and use full paths if possible.. it will save you every time.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
You can get the paths yourself by examing the ENV variables. Run this from a browser:

Code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";

foreach my $var (sort keys %ENV) {
    print "<b>$var</b> = $ENV{$var} <br>\n";
}


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Good call Kevin.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
well after a lot of faffing around I've finally got it to work.

Thanks again and Happy christmas!

Ant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top