Jump to content

Using PHP to modify a file, getting errors


Thoth2020

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.