Jump to content

Archived

This topic is now archived and is closed to further replies.

Thoth2020

Using PHP to modify a file, getting errors

Recommended Posts

I am trying to create a page with newspost functionality, wherein the user can type a subject and body, and it will be put at the top of a news.php page which is included in another index.php page.  I was getting permission denied errors, so I thought I would use chmod(), but I am getting the following errors.

[code]Please wait...
Warning: chmod(): Operation not permitted in /Sites/Tear Gas Media/dopost.php on line 9
This is a test to see if my news include idea actually works.
Warning: fopen(news.php): failed to open stream: Permission denied in /Sites/Tear Gas Media/dopost.php on line 9

Warning: fwrite(): supplied argument is not a valid stream resource in /Sites/Tear Gas Media/dopost.php on line 10[/code]

I am running Apache on Mac OS X 10.3.9, and safe mode is off.

Here is the code of the page that is supposed to execute the actual posting:

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
echo "Please wait...";
$day = getdate(date("U"));
$old = file_get_contents("news.php");
chmod("news.php","0777");
echo $old;
$file = fopen("news.php","w+");
fwrite($file,"$day[month] $day[mday]" . "\n" . $_POST["subject"] . "\n" . $_POST["news"]
. "\n" . $old);
?>
</body>
</html>
[/code]

I guess, basically, my question is, why can't I access this file, given that safe mode is off?  chmod doesn't want to work, dangitall, and that's causing the other errors.

Share this post


Link to post
Share on other sites
Removing the quotes resulted in the same error "Warning: chmod(): Operation not permitted in /Users/tedpolak/Sites/Tear Gas Media/dopost.php on line 9"

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.