PDA

View Full Version : fopen Permissions error PHP w/ Mac OS X 10.3


3dmacguy
08-03-2004, 04:41 AM
Hi,

I am passing a variable successfully from Flash to a php script. The php script, I believe, is fine. The PHP script accepts the variable and attempts to open, write, and then close an XML file.


<?php
$data = $HTTP_POST_VARS["news"] . "\r\n";
$filename = "newsxml.xml";

//Imports old data
$handle = @fopen($filename, "r");
$old_content = fread($handle, filesize ($filename));
fclose($handle);

//Sets up new data
$final_content = $data.$old_content;

//Writes new data
$handle2 = fopen($filename, "w");
$finalwrite = fwrite($handle2, $final_content);
fclose($handle2);
?>


When I try to pass the variable to the PHP page, though, I get this error message....

Warning: fopen(newsxml.xml): failed to open stream: Permission denied in /Library/WebServer/Documents/josh/writexml.php on line 11

Warning: fwrite(): supplied argument is not a valid stream resource in /Library/WebServer/Documents/josh/writexml.php on line 11

Warning: fclose(): supplied argument is not a valid stream resource in /Library/WebServer/Documents/josh/writexml.php on line 11

I know the variable is being passed as it echos back fine. But it seems there are some permissions errors. I am completely new to using PHP and setting permissions. I am running Mac OS X 10.3 and am using the default configuration of Apache w/ the PHP module supplied from Apple. Serving from 'Library/WebServer/Documents/myFolder'. Any idea why I cannot fopen, fread, or fclose a file?

Thanks. Been stuck on this all day.
-Josh

CyanBlue
08-03-2004, 04:14 PM
Uh... The only thing I could think of is to change the permission of the 'newsxml.xml' to 666... I am not sure how that thing works in Mac, but I guess you could still use chmod to do that???
Oh... Make sure that the file actually exists as well...

3dmacguy
08-03-2004, 04:49 PM
Hey, see my other post in the AS2 forum. But it ended up being a permissions error like you said. Stupid mistake I guess. Set the XML file to 'read and write' as opposed to just 'read'. It's always the little things :) Problem solved. Thanks.

-Josh

CyanBlue
08-03-2004, 04:57 PM
Oh... Simple... That's good... :)
(It's not nice to post threads with the same question... You know that, right??? :D)

3dmacguy
08-04-2004, 05:48 PM
I do now. Won't happen again. I'll go sit in the corner now :D

-Josh

CyanBlue
08-04-2004, 06:03 PM
Okay... That's enough... You can stand up now... :D