in reply to CGI troubles - not writing to file
#!/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 | |
by amphiplex (Monk) on Jul 01, 2002 at 08:57 UTC |