File opening problems

Discussion in 'PHP' started by ManXP, Sep 8, 2007.

  1. #1
    I have an application which has such a piece of code inside:

    
    if (!file_exists("some_file.php"))
        {
        echo "Something wrong...";
        }
    
    PHP:
    So it just checks if some_file.php is uploaded to the same directory where application is installed. I've been using it for 12+ months on different and everything was fine. Yesterday one of customers reported that application doesn't work.

    I checked it, and application could not find this file (but file EXISTS!) on customer's server. Then I did another check - wrote a line of code:

    $file=fopen("whatever.txt", "w");
    PHP:
    Surprise surprise, file "whatever.txt" was not found by application again, even if it was uploaded to same directory. My application works fine on hundreds of different servers, and this is the 1st time when customer has issues. Server is powered by freebsd and uses DirectAdmin.

    Personally I guess it's related to include_path settings in php.ini file, but may be I'm wrong? What may cause this problem and how could I force application to open file from existing directory?

    I know I could write full path like
    $file=fopen("/home/some_username/public_html/some/directory/whatever.txt", "w");
    PHP:
    but this is not a solution.

    I'm waiting for ANY ideas and suggestions.

    Thanks!
     
    ManXP, Sep 8, 2007 IP
  2. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Try supplying all the /htdocs/public_html/ etc part of the file path?
     
    Synchronium, Sep 8, 2007 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Two things:

    * File on server contains unseen foreign characters (it can happen).
    * User did something on the server to stop such actions (maybe disabled in php.ini or an application).

    Peace,
     
    Barti1987, Sep 8, 2007 IP
  4. greys

    greys Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi there!

    Check the log files for the web server, by the look of it your client has their PHP running in safe mode, which imposes a number of restrictions.

    One of such restrictions is that the file (or directory) you're trying to access should be owned by the same UID (user id) that your webserver is running under.

    In other words, you need to use a web control panel to create the test file, not upload it through FTP. This way, the file will belong to the user id of your webserver and not the actual user id of your customer.

    In logs for Apache, look for something similar to this:

    Warning: file_exists() [function.file-exists]: SAFE MODE Restriction in effect. The script whose uid is <1234> is not allowed to access /home/customer123/public_html/<file.txt> owned by uid <123> in /home/customer123/public_html/test.php on line <111>
    PHP:

    you're most likely affected by the PHP safe mode, which means it could possible have prohibited you accessing the directories you're in.

    PM me if you need help with this! Good luck!
     
    greys, Sep 8, 2007 IP