sysopen problem

  • Thread starter Hon Guin Lee - Web Producer - SMI Marketing
  • Start date
H

Hon Guin Lee - Web Producer - SMI Marketing

My objective is to open a file if it exists, and if not create a new file from the string variable $FILE, but I have encountered a problem that in some occurences the file can be opened and modified without the compiler throwing error messages otherwise it throws a Permission Denied error (not owner) from just modifying a file within the local web server.

# open the file and allow it to be modified.
# modify file by adding the content or create a new file.

open($FILE, "> $page") || die $!;
sysopen($FILE, $page, O_WRONLY|O_CREAT) || die $!;
sysopen($FILE, $page, O_WRONLY|O_CREAT, 0777) || die $!;

OR

sysopen($FILE, $page, O_WRONLY | O_CREAT, 0777) || die $!;
 
K

ko

Hon Guin Lee - Web Producer - SMI Marketing said:
My objective is to open a file if it exists, and if not create a new file from the string variable $FILE, but I have encountered a problem that in some occurences the file can be opened and modified without the compiler throwing error messages otherwise it throws a Permission Denied error (not owner) from just modifying a file within the local web server.

# open the file and allow it to be modified.
# modify file by adding the content or create a new file.

open($FILE, "> $page") || die $!;
sysopen($FILE, $page, O_WRONLY|O_CREAT) || die $!;
sysopen($FILE, $page, O_WRONLY|O_CREAT, 0777) || die $!;

OR

sysopen($FILE, $page, O_WRONLY | O_CREAT, 0777) || die $!;

This isn't the right way to open the file the way you want to. It will
destroy any data in an existing file, not add/append. From
'perlopentut':

To open a file for appending, creating one if necessary:

open(FH, ">> $path");
sysopen(FH, $path, O_WRONLY | O_APPEND | O_CREAT);

The rest of the problem is in the error message. You have a
permissions problem. Identify the user account that the program is
running under, and you should have your answer.

HTH - keith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top