www.webdeveloper.com
Results 1 to 2 of 2

Thread: php apache file ownership and creation problem

  1. #1
    Join Date
    Apr 2006
    Posts
    245

    php apache file ownership and creation problem

    I am trying to do a really basic rename of a file to another name in my code. However there seems to be some ownership/permissions problem that is stopping this working correctly.

    This is my (simplified) code:

    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL);

    $St_Num '7940';
    $Co_Code 'RDCO2';

    rename("$St_Num-$Co_Code-1.jpg""$St_Num-$Co_Code-4.jpg"); 
    These are my permissions of the files I am trying to change:

    Code:
    -rw-r--r-- 1 apache dev   4065 Oct 22 17:57 7940-RDCO2-3.jpg
    -rw-r--r-- 1 apache dev   4276 Oct 28 09:39 7940-RDCO2-2.jpg
    -rw-r--r-- 1 apache dev   4336 Oct 28 09:39 7940-RDCO2-1.jpg
    This code was working, and it seemed to work when apache was the *creator* of the file. However, when I changed the ownership to 'apache' it stopped working. Does PHP/Apache have a concept of knowing who the creator of a file was? Would this stop a rename() from working?

    I'm stumped with this one now - any help is appreciated.

    Thanks,
    Picco

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,357
    In most typical web host environments, PHP runs as an Apache module, and thus your scripts are executed under the Apache user. So if the file is owned by some other user, such as your personal login/FTP account, PHP functions such as rename() will only work on files created by another non-Apache user (e.g. you) if the file permissions include read and write for all users (666 or 777 in Linux/UNIX terms, or possibly 664 or 774 if the file owner and Apache share a user group).

    So, if a file is created by your PHP script, then it is owned by the Apache user and can by default be rename()'d by it, but if created by your login user or other non-Apache user, then you need to give it the necessary permissions before your PHP script can modify it (assuming again that the script is being executed by Apache as is typically -- but not always -- the case).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles