PHP issues with file ownership

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a PHP script which creates new text files in the same directory
as itself.  The new files are also PHP scripts and are built with a
line of code within them, which runs a function when they are browsed
to by the user.

E.g. the new file's contents are similar to <?php runFunction(83); ?>

However, because the new file was created by a script, it does not
have the same owner as the and the function fails. An exact copy of
the file uploaded from my FTP software works fine as it has the same
owner as my script.

The error I receive is that there is a safe mode restriction and the
uid/gid does not match.

I use a shared server, so am reluctant to edit the php.ini file.

I have tried to 'chown' the file after creation but it fails,
(probably because my script is not superuser).

I am running out of ideas, is there another way to change the
ownership to match? Or are there any other options that I can

Thanks in advance,

Re: PHP issues with file ownership

On 15.05.2007 23:54 joniboy123 wrote:
Quoted text here. Click to load it

The simplest way to get around "safe mode" is to change the owner of  
main script to www or whatever user your apache runs as. Create a file  
"generate.php" with something like

<?php file_put_contents('index.php',
main script goes here...

upload "generate.php" and run it once. You'll get "index.php" owner by  
"www", so it will have full access to other www's files.

gosha bine

extended php parser ~
blok ~

Re: PHP issues with file ownership

Quoted text here. Click to load it

But you can administer the server? There are some special permissions
you can set on a directory. One of them is that you execute the file or
directory as the user or group that created it. For directories, this
means that you create files as the directory owner or as member or the
directory's group. See the chmod man page.

Best regards,
Willem Bogaerts

Application smith
Kratz B.V.

Site Timeline