Click to See Complete Forum and Search --> : How to edit files with PHP in safe mode?


gopher292
01-13-2006, 11:15 AM
Hello,

I'm trying to make a 4.x.x php script that outputs a file and have this code:<?php

$output="<html><head><title>test</title></head><body>test</body></html>";
file_put_contents("test.txt", $output);

function file_put_contents($file, $output) {
touch($file);
$handle=fopen($file, 'w');
fwrite($handle, $output);
fclose($handle);
}

?> But when I run it on my free php host I get the following error:
Warning: touch(): SAFE MODE Restriction in effect. The script whose uid is 502 is not allowed to access /vhost/usr/megasearch owned by uid 48 in /vhost/usr/megasearch/test.php on line 7

Warning: fopen(): SAFE MODE Restriction in effect. The script whose uid is 502 is not allowed to access /vhost/usr/megasearch owned by uid 48 in /vhost/usr/megasearch/test.php on line 8
.
.
.

I don't have access to php.ini but I can change and add files with FTP.

How can I have the script run without the safe mode restrictions?
Is there a way that I can have the script run as "me" instead of as a script owned by me?

Thanks

chazzy
01-13-2006, 11:35 AM
what are the permissions on the file btw?

gopher292
01-13-2006, 11:50 AM
I've set the file permissions on the php script to 755. It didn't work with 644 either, though.
And the file it's writing to doesn't exist yet, the script is creating the file.

NogDog
01-13-2006, 12:11 PM
In safe mode, the directory in which you are doing these operations will need to be owned by the same user under whom the PHP script is run. In Apache installations, this is typically a user called "nobody". You'll probably have to have a sysadmin do a chown on the directory you want to use for these script actions (or they may just want to create a new directory for you for this purpose).

PS: lots of info at http://www.php.net/manual/en/features.safe-mode.php

gopher292
01-13-2006, 02:59 PM
I chmodded the folder the script was in to 775 and now it works. Thanks for all the help. :)