#32503 [Fbk->Opn]: fopen() in cwd: filename must start with ./ under safe mode
| From: | Bjorn dot Wiberg at its dot uu dot se | Date: | Fri, 01 Apr 2005 14:32:36 +0000 |
| Subject: | #32503 [Fbk->Opn]: fopen() in cwd: filename must start with ./ under safe mode | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-76172@lists.php.net to get a copy of this message | ||
ID: 32503
User updated by: Bjorn dot Wiberg at its dot uu dot se
Reported By: Bjorn dot Wiberg at its dot uu dot se
-Status: Feedback
+Status: Open
Bug Type: Filesystem function related
Operating System: IBM AIX 5.2.0.0 ML5
PHP Version: 5.0.3
New Comment:
Tried php5-200503310630 (5.1.0-dev), but the problem is still present:
/apache/htdocs/bwiberg/test/safemode
Warning: fopen(): Unable to access a.txt in
/apache/htdocs/bwiberg/test/safemode/write.php on line 5 Warning:
fopen(a.txt): failed to open stream: No such file or directory in
/apache/htdocs/bwiberg/test/safemode/write.php on line 5
(Whereas "./a.txt" works just fine.)
Best regards,
Björn
Previous Comments:
------------------------------------------------------------------------
[2005-03-30 17:17:27] sniper@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
------------------------------------------------------------------------
[2005-03-30 14:37:04] Bjorn dot Wiberg at its dot uu dot se
Description:
------------
Under safe mode, if one tries to create a new file with fopen(),
specifying a filename without any path part in it (such as "./a.txt" or
/apache/htdocs/bwiberg/test/safemode/a.txt"), fopen() fails, claiming
that the file cannot be found.
If the file already exists, everything works just fine.
If you specify a path part ahead of the filename, everything works just
fine.
If you give fopen() "true" as a third argument, and make sure that your
include_path includes "." as its FIRST path (if you have several
directories in it), everything works just fine. (Perhaps the
restriction of only trying the FIRST path should be mentioned in the
docs as well.)
I'm not sure if this problem is related to the earlier discussions of
php_realpath_hack (that fix should be present as "_AIX" is set by gcc
under AIX), but it sure poses a problem for scripts which rely on being
able to create a file in the current directory without specifying any
path.
Another question is why $handle in the example script isn't set to
FALSE if the open failed -- instead the error propagates to the fputs()
part.
I'd appreciate any input regarding this. Thanks in advance!
Best regards,
Björn
Reproduce code:
---------------
<?php
print getcwd() . "<BR>";
$handle = fopen("a.txt", "w", false);
if ( $handle != FALSE ) {
fputs($handle, "testtext");
fclose($handle);
}
?>
Expected result:
----------------
/apache/htdocs/bwiberg/test/safemode
(File a.txt gets created in current directory.)
Actual result:
--------------
/apache/htdocs/bwiberg/test/safemode
Warning: fopen(): Unable to access a.txt in
/apache/htdocs/bwiberg/test/safemode/write.php on line 5 Warning:
fopen(a.txt): failed to open stream: No such file or directory in
/apache/htdocs/bwiberg/test/safemode/write.php on line 5
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32503&edit=1