Can't Write to Files? 
Author Message
 Can't Write to Files?

$path = "/home/user1/public_html/files/";

sub PrintEnter{

#submit customer info to text file
$file = "$path" . "customers.txt";
if (-e $file) {                                   #if the file exists...
print "$file<BR>exists";                  #checksum to see if it reaches
this if statement
  open(DAT, ">>$file");                #open the file for appending

Quote:
}

else {
print "$file<BR>does not exist";    #checksum to ensure it reaches this else
statement
  open(OUTF,">$file");                 #open the file for output

Quote:
}

print OUTF "$username|$customer\n";
close(OUTF);

Quote:
}

I continue to get the checksum for the else statement through the browser:

/home/user1/public_html/files/customers.txt
does not exist

It never creates the file and if I create the file myself and run it I get
the same thing files does not exist and yes it is pathed correctly, I went
as far as doing a pwd to get the current directory and cutting and pasteing
it into the script.  I'm loosing my mind!!



Sat, 27 Oct 2001 03:00:00 GMT  
 Can't Write to Files?

Quote:

> I continue to get the checksum for the else statement through the browser:

> /home/user1/public_html/files/customers.txt
> does not exist

> It never creates the file and if I create the file myself and run it I get
> the same thing files does not exist and yes it is pathed correctly, I went
> as far as doing a pwd to get the current directory and cutting and pasteing
> it into the script.  I'm loosing my mind!!

First, your problem is a cgi one, not a perl one so this should be asked
in the cgi newsgroup comp.infosystems.www.authoring.cgi

Second, I would check the permissions of the file against the permissions that
the webserver is running under.  Your problem may lie there.

Kent



Sat, 27 Oct 2001 03:00:00 GMT  
 Can't Write to Files?
Jerry Raynor

Quote:

>   open(DAT, ">>$file");                #open the file for appending

[snip]

Quote:
>   open(OUTF,">$file");                 #open the file for output

[snip]

Quote:
> It never creates the file [snip]

Always, always, always check the success of open.  And always ask why it
failed if it fails.

    open(OUTF,">$file") || die "Can't open '$file': $!\n";

This will tell you what your problem is better than anyone here can
guess.  And it works for many other functions too.

perldoc -f open

Also check perlfaq3, "How do I debug my Perl programs? ".

--
Rick Delaney



Wed, 31 Oct 2001 03:00:00 GMT  
 Can't Write to Files?
[posted & mailed]

Quote:

> First, your problem is a cgi one, not a perl one so this should be asked
> in the cgi newsgroup comp.infosystems.www.authoring.cgi

I don't see how this is a CGI problem.  It is a debugging problem.

Quote:
> Second, I would check the permissions of the file against the permissions that
> the webserver is running under.  Your problem may lie there.

It may, but it is usually a good idea to start with common debugging
techniques to reduce the number of wild guesses that need to be made.

My other post in this thread shows one such common technique and no wild
guesses.  :-)

--
Rick Delaney



Wed, 31 Oct 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 'seek'ing in a file before writing

2. Apache, embperl, mod_perl : require doesn't work and can't write to file

3. can't write to file descriptor during infinate loop

4. Newbie Question: Can't write file in data directory of a Win2000 server

5. Script won't write to file or change directory

6. Can't write big file.

7. Can't write big file

8. Image::Magick->Write() doesn't want to write

9. Can't write a LOG file, please help

10. My cgi can't write in a file

11. writing to db file fails even though the open doesn't

12. Include file : can't get perl to write to webpage

 

 
Powered by phpBB® Forum Software