开发者

PHP can't read filename which has special character !

开发者 https://www.devze.com 2023-01-29 00:41 出处:网络
i have problem with file() in php. The function can\'t read a file start with ! or $ like !textfile.txt or $textfile.txt, i try wit开发者_Python百科h fopen() and it happen as a same way. I have no ide

i have problem with file() in php. The function can't read a file start with ! or $ like !textfile.txt or $textfile.txt, i try wit开发者_Python百科h fopen() and it happen as a same way. I have no idea how to solve this. I hope someone can help Appreciate any help.


The filename "$textfile.txt" will not work as expected because variable interpolation happens in double quotes as a result value of variable $textfile will be appended with .txt and the result will be used as filename. If $textfile is undefined (which mostly is the case), .txt will be used as the filename.

To fix this use single quotes around the filename as '$textfile.txt' or if you have to use double quotes, escape the $ as: "\$textfile.txt"

But I see no problem with "!textfile.txt"


echo file_get_contents("\$test.txt");

Works.

You need to escape special characters or use single quotes.

0

精彩评论

暂无评论...
验证码 换一张
取 消