logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



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

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Perl CGI script cannot write file

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
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: 6202
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


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1