logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Perl CGI script cannot write file
Author
michagal



Joined: 29 May 2016
Posts: 1

PostPosted: Sun 29 May '16 15:21    Post subject: Perl CGI script cannot write file Reply with quote

Hello,
I started a new Apache web server Apache/2.4.6 (CentOS) and trying to reuse old scripts. One of the scripts has to write a file on a server. I opened a directory under cgi-bin and gave all permissions.

drwxrwxr-x. 2 user user 6 May 29 2016 docx2regs

Still, the script give me "Permission denied" error when it attempts to write a file to it.
The same script is capable to write to the directory when I run it manually. I assume some definitions are missing from conf.httpd.
Help will be appreciated.
Thank you.

Code:

#!/usr/bin/perl

use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;

print header;
print start_html(-title => "Test");

print <<header2;
<center>
<h1> Hello
</center>
<hr>
header2

my $filename = "docx2regs/test.txt";
open(my $FILE, ">$filename");

if(-e $filename) {
        print "$filename exists\n";
        print $FILE "Hello\n";}
else {
        print "$filename does not exist\n";}

close($FILE);

print end_html;


When I open the test.pl in browser I get "docx2regs/test.txt does not exist" message. When I run the test.pl in cgi-bin directory the file is created.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Sun 05 Jun '16 18:25    Post subject: Reply with quote

You can try to use the full path or start with ./ to refer to the current folder.
Back to top


Reply to topic   Topic: Perl CGI script cannot write file View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner