| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2004-02-03 10:01 UTC] kulpp at wsg dot net
 Description:
------------
Back in 4.0.3, tempnam() was changed to actually create the temp file to avoid a race condition. It would seem that the current implemntation is inconsistent with SAFE MODE restrictions which then prevent access to the filename returned by tempnam().
Reproduce code:
---------------
<%
$filename = tempnam('', 'test_');
fopen($filename, 'r');
%>
Expected result:
----------------
no errors or warnings
Actual result:
--------------
Warning: fopen(): SAFE MODE Restriction in effect. The script whose uid is 579 is not allowed to access /tmp/test_zSTbRQ owned by uid 18 in /usr/local/www/docs/test/tempnam_broken.php on line 5
Warning: fopen(/tmp/test_zSTbRQ): failed to open stream: Permission denied in /usr/local/www/docs/test/tempnam_broken.php on line 5
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 01:00:02 2025 UTC | 
I understand the documentation on the first parameter. I am intentionally relying on the rest of documentation that states that it will use the system default temp space in this case. PS: it exhibits the exact same behaviour with tempnam('\tmp', 'test_') The temp file IS being created, but it's not owned with the correct UID. Doesn't this behaviour make the tempnam function useless under SAFE MODE?$filename = tempnam('\tmp', 'test_'); fopen($filename, 'r'); still produces Warning: fopen(): SAFE MODE Restriction in effect. The script whose uid is 579 is not allowed to access /tmp/test_YNsKKT owned by uid 18 in ...