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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing .txt files outside of CGI directory (apache/win98se) ???

Status
Not open for further replies.

kickinpretty

Technical User
Jul 26, 2002
17
GB
Hi all

i need some help with this its driving me mad...basically i have a cgi that writes a new file when activated. the cgi is as follows...

#!C:\Program Files\Abria Merlin\Perl\bin\perl

require "subparseform.lib";
&Parse_Form;

$n1 = $formdata{'n1'};

@New = ("n1=$n1");

open (LOG, ">\test1.txt") || &ErrorMessage;
print LOG "@New";
close (LOG);


print "Content-type: text/html\n\n";
print "Status=Success - You are now a registered user";

sub ErrorMessage {
print "Content-type: text/html\n\n";
print "Status=Connection Failed Please Check the path to the text File";
exit;
}

This works fine by writing a text file inside the cgi-bin, if i change the following line...

open (LOG, ">\test1.txt") || &ErrorMessage;

to...

open (LOG, ">\\test1.txt") || &ErrorMessage;

It writes a file at C:\ this works fine to, but what i want to do is write a file to a directory called \site the full path to this is...

C:\Program Files\Abria Merlin\Apache\htdocs\site\test1.txt

I have tried every combination of file paths and even tried absolute file paths with no joy.

WHAT AM I DOING WRONG????????
 
Does your open look like

open(LOG, ">C:\Program Files\Abria Merlin\Apache\htdocs\site\test1.txt") || &ErrorMessage;

???

What error message(s) are you getting?

Not sure about Windows, but on *nix, you need to ensure that the user("apache" or "nobody" or ???) running the webserver has permission to write to the target directory - and that may(?) require certain permissions for each directory above the target directory.

Also, I just did 'perldoc perl' at a command prompt and then did a search(using the forward slash "/") for "windows" and found that there is a perldoc for Windows. At a command prompt, do

perldoc perlwin32

and that will provide some notes on using Perl on Windows. I wouldn't be surprised if there was info in there about path and filenames on Windows.

HTH. Hardy Merrill
 
Hi thanx for the reply...

The problem was the path should have had forward slashes "/"instead of backward slashes..."\"

its working sweet as now :)
 
How did you figure that out? I just looked through the 'perldoc perlwin32' and I didn't see anything like that - I couldn't really find anything on windows paths needing the directories separated by *forward* slashes. I'm confused ;-) Hardy Merrill
 
Forward slashes or \\, since \ just escapes the character following it. //Daniel
 
How did you set the permmisions so that the CGI could write to a file, I am having trouble with this one!
I am running Apache on Windows 2000.

thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top