Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: CGI troubles - not writing to file

by emilford (Friar)
on Jun 30, 2002 at 15:41 UTC ( [id://178375]=note: print w/replies, xml ) Need Help??


in reply to CGI troubles - not writing to file

Okay, I just wrote a quick little test script that should work as far as I can tell. I copied the functions exactly as they were in the original script, restored my index file, and then ran the script. The result, a blank backup.html file. What gives?
#!/usr/bin/perl -w use strict; my $index = '../index.php'; # the main page + to be edited my $index_backup = '../edit/backup.html'; # the main pa +ge backup my $url = 'http://www.mywebsite.com/edit/backup.html'; &back_up_file ($index, $index_backup); &redirect ($url); # makes an exact copy of the current index file - security incase some +thing # were to go wrong when adding the news entry sub back_up_file { my ($index, $index_backup) = @_; # open the necessary files needed for reading and writing open (INDEX, "<$index") or die &show_error ("Unable to open $index +: $!"); open(BACKUP, ">$index_backup") or die &show_error ("Unable to open + $index_backup: $!"); # write the existing file into the backup while (<INDEX>) { print BACKUP "$_"; } # close the files close (INDEX); close (BACKUP); } # redirects the user to the updated index page - or wherever specified sub redirect { use CGI qw(:cgi); my $url = $_[0]; my $q = CGI->new(); print $q->redirect( -url => $url ); } # shows the error returned inside of the browser - easier debuging sub show_error { print "Content-type: text/html\n\n"; print "This is the error: <h1>$_[0]</h1>"; exit(0); }

Replies are listed 'Best First'.
Re: Re: CGI troubles - not writing to file
by amphiplex (Monk) on Jun 30, 2002 at 20:50 UTC
    That's really strange, your script worked for me (perl 5.6.1, apache 1.3.20) !

    Could there be a problem with the relative paths to the files ?

    ---- kurt
      One suggestion that could solve this mystery:
      Try to catch the error of close(BACKUP):
      close(BACKUP) or show_error ("error closing [$index_backup]: $!");
      It is generally a good idea to check even close for errors.

      ---- kurt

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://178375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-16 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found