Jump to content


Photo

Using PHP to modify a file, getting errors


  • Please log in to reply
4 replies to this topic

#1 Thoth2020

Thoth2020
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 September 2006 - 12:53 AM

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.

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

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:

<!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>

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.

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 30 September 2006 - 03:02 AM

Have you made sure the file that's running has the same owner as the file you're trying to chmod.

#3 Thoth2020

Thoth2020
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 September 2006 - 06:20 AM

Yes, both files have the same owner.

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 30 September 2006 - 03:48 PM

try the 0777 without quotes.

#5 Thoth2020

Thoth2020
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 01 October 2006 - 03:34 AM

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"




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users