|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81336 & in filename doesn't read file with file
Submitted: 2021-08-06 10:49 UTC Modified: 2021-08-06 12:10 UTC
From: remco dot pc at outlook dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: 8.0.9 OS: win10 - wsl ubuntu-200.4 LTS
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.
Block user comment
Status: Assign to:
Bug Type:
From: remco dot pc at outlook dot com
New email:
PHP Version: OS:


 [2021-08-06 10:49 UTC] remco dot pc at outlook dot com
when a filename has an ampersand in it (&) the file exist is true, but file read with file() or file_get_contents doesn't read the file

Test script:
$read = file('test&.mp3');


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-06 10:57 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-08-06 10:57 UTC]
I cannot reproduce this on Windows with PHP-7.4.  Either it is PHP
8 specific, or it doesn't affect Windows.  Please tell us which OS
you are using.
 [2021-08-06 11:06 UTC] remco dot pc at outlook dot com
os, win10 - wsl ubuntu-200.4 LTS
 [2021-08-06 11:43 UTC]
-Operating System: +Operating System: win10 - wsl ubuntu-200.4 LTS
 [2021-08-06 11:43 UTC]
I cannot reproduce with PHP-8.0 on WSL running Debian 9.13 on
Windows 10 either; neither with the file on the host nor in the
guest.  Do you get any warning or notice (I assume you have
error_reporting=-1)?  Can you provide further info which may help
to make the issue reproducible?
 [2021-08-06 11:57 UTC] remco dot pc at outlook dot com
i did a mistake, php version 8.0.8.
@ sign in file name is ok and reading.
& sign is not reading the file.
i don't get any error messages reading the file.
 [2021-08-06 12:10 UTC]
-Status: Feedback +Status: Open -Assigned To: cmb +Assigned To:
 [2021-08-06 12:10 UTC]
I checked with & not @.  Without further info, I can't help.
 [2021-08-16 00:04 UTC] antonino dot spampinato86 at gmail dot com
Creating/modifying any files within the Linux subsystem using Windows apps & tools can cause Data corruption and data loss in Ubuntu subsystem! (Thanks to Rich Turner for suggesting these words of caution!) This is absolutely not supported. From the same blog post:

Interoperability with Windows
While VolFs files are stored in regular files on Windows in the directories mentioned above, interoperability with Windows is not supported. If a new file is added to one of these directories from Windows, it lacks the EAs needed by VolFs, so VolFs doesn’t know what to do with the file and simply ignores it. Many editors will also strip the EAs when saving an existing file, again making the file unusable in WSL.

$file = __DIR__ . '/file\\&.mp3';
$result = file($file);
$error = error_get_last();
var_dump($error, htmlspecialchars($file), is_array($result));

//Correct Error output example
/*Warning: file(/my_path/file\&.mp3): Failed to open stream: No such file or directory in /my_path on line 5
array(4) {
  string(70) "file(/my_path/file\&.mp3): Failed to open stream: No such file or directory"
  string(8) "/my_path"
string(23) "/my_path/file\&.mp3"

AMPERSAND is a reserved character on WINDOWS, you can search for it enclosed in quotes or backslashes (natively on Windows). You can try with backslash. Was the file created by php or by Ubuntu? Can you show more details?

Note* HTML output (browser) & current display to &, but it entity character
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 02 09:05:53 2022 UTC