|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-08-06 10:49 UTC] remco dot pc at outlook dot com
Description:
------------
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');
dd($read);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 04:00:02 2025 UTC |
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. error_reporting(-1); $file = __DIR__ . '/file\\&.mp3'; $result = file($file); $error = error_get_last(); error_clear_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) { ["type"]=> int(2) ["message"]=> string(70) "file(/my_path/file\&.mp3): Failed to open stream: No such file or directory" ["file"]=> string(8) "/my_path" ["line"]=> int(5) } string(23) "/my_path/file\&.mp3" bool(false)*/ 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