
yapp
User
Apr 18, 2002, 9:57 AM
Views: 281
|
|
Re: [alalleyn] Obtaining information forms
|
|
|
- There are single quotes arround your filename!! open() fails! The script returns an error. The webserver doesn't send the message to the browser, since it's not a HTTP header. Bad luck i'd say. use #!/usr/bin/perl -w This is a great debugging tool! If you have problems with understanding the error messages: - use diagnostics; It's recommended to declare all variables with my() first use strict; forces you to do that! my($x) = value; use CGI::Carp qw(fatalsToBrowser) - You'll see a lot of compiler messages (if you had any problems) use: open(...) or die "can't open the file: $!"; - Not checking the result of any IO isn't good. Don't forget the lock the file! use Fcntl qw(:flock); - before reading do: flock(TXT, LOCK_SH); - before writing do: flock(TXT, LOCK_EX); - before appending do: flock(TXT, LOCK_EX); seek(TXT, 0, 2) or die "Can't seek new EOF: $!"; # File size might changed after lock was released! You're using the CGI module, why not using the header() method??? print $query->header('text/html'); So in other words:
#!/usr/bin/perl -w use strict; use diagnostics; use CGI(); use CGI::Carp qw(fatalsToBrowser); use Fcntl qw(:flock); my $query = new CGI; my $file = $query -> param('file'); open (TXT, $file) or die "Can't open $file: $!"; flock(TXT, LOCK_SH); # no one can edit the file now. my @text = <TXT>; close (TXT); open (DATA, ">>xmlWeave.xml") or die "Can't open xml: $!"; lock(DATA, LOCK_EX); # waits until no-one uses the file, and blocks it then. seek(DATA, 0,0) or die "Can't seek new EOF: $!"; print DATA @text; # all in once; print can handle array's close(DATA); print $query -> header('text/html'); print <<HTML_PAGE; # nice <<HERE; block <html><h1> A Documentation file has been created!</h1> Please open xmlWeave in a broswer to see complete documentation file </html> HTML_PAGE Voila! PS. what will happen if your users call your script like this: script.cgi?file=/etc/passwd This might be something you want to watch out for! Good luck! Yet Another Perl Programmer _________________________________ ~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~ More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads!
(This post was edited by yapp on Apr 18, 2002, 10:00 AM)
|