Search code examples
phpdirectorychmodchownfile-ownership

PHP Creating folder with the owner as 99


I have a script (run as a cron) that creates a new folder called images on a server and moves images from the root folder to this new folder. Later another function will create thumbnails from these images and places these into another new folder named thumbs inside that same folder.

However, this function will only work if the parenting images folder has the owner set to 99 for some strange reason. The folder gets the user as its default owner.

How can I get the script to create a folder with the owner set to 99? Or what could be the reason that the PHP script has no power of chmod-ing files that have the user as the owner?


Solution

  • Apparently it depends on how the php script was run in the cronjob to determine which owner will be set as the default on newly created files.

    First I used:

    /usr/local/bin/php /home/username/public_html/script.php > /home/username/public_html/file.xml 2>&1
    

    But this created new folders with the owner set to the 'username'.

    Instead using curl:

    /usr/bin/curl -s http://domain.com/script.php > /home/username/public_html/file.xml 2>&1
    

    Allowed the new files/folders to be created with the owner set to nobody (UID 99) which in its turn allowed the next script to create new folders/files inside this folder without a problem.