php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-06 10:57 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-08-06 10:57 UTC] cmb@php.net
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] cmb@php.net
-Operating System: +Operating System: win10 - wsl ubuntu-200.4 LTS
 [2021-08-06 11:43 UTC] cmb@php.net
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] cmb@php.net
-Status: Feedback +Status: Open -Assigned To: cmb +Assigned To:
 [2021-08-06 12:10 UTC] cmb@php.net
I checked with & not @.  Without further info, I can't help.
Sorry.
 [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.

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
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 20 13:03:32 2021 UTC