php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64327 is_file, file_exists, is_readable fail on special characters
Submitted: 2013-02-28 20:32 UTC Modified: 2013-06-19 11:33 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: ashwini at majestik dot net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: Irrelevant OS: Windows Server 2003
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ashwini at majestik dot net
New email:
PHP Version: OS:

 

 [2013-02-28 20:32 UTC] ashwini at majestik dot net
Description:
------------
---
From manual page: http://www.php.net/function.is-file#refsect1-function.is-file-description
---
The is_file, file_exists and is_readable functions fail in Windows even if the file actually does exist, if the file name contains a special character. This happens because of the encoding of the .php file itself that executes the is_file function, if the .php file is encoded with UTF-8 then the above commands incorrectly fail.

If instead the .php file is encoded with "Western (Windows 1252)" then the file with the special character is found and is_file/file_exists/etc return correctly.

Tested under IIS 6 w/ PHP 5.2.4 on Windows Server 2003.

Test script:
---------------
<?
$my_picture="photos/fullsize/DjaƱgo.jpg";

if (is_file($my_picture)) { 
      echo "picture found!";
    } else { 
      echo "picture NOT found! $my_picture";
    }
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-19 11:33 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2013-06-19 11:33 UTC] ab@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Ok, so even not tested as your description delivers the solution. If the php file 
is utf8 encoded, the special char is represented with at least two bytes. If the 
real filename happens to use a single byte charset like cp1252, here you are. That 
doesn't mean you cannot use utf8 encoded sources, just care you always convert the 
filename to the right charset.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 04:01:31 2024 UTC