File_exists () for a file that contains (&) in the file name

$filename = "Sara & I.mp3";
if (file_exists($filename)) {
 ...
}

If the file name has " &", PHP does not return true forfile_exists

How can I escape the " &" in $ filename for file_existsto work?

Already I tried urlecode(), urlrawencode(), htmlentities()and escaped '&' with a backslash (\ &) ... no go

ps. it's on a linux system running redhat5

early

+3
source share
5 answers

It seems to me that the script is working for me.

Make sure the file you are checking is in the directory where your script is running.

getcwd(), , script.

. script /scripts/ script.php script my/other/scripts/index.php, script my/other/scripts, my/scripts,

+2

? , A-Z, 0-9 _ - , .pdf, charachters. _.

TYPO3, CMS PHP, , :

$fileName = preg_replace('/[^.[:alnum:]_-]/','_',trim($fileName));  // converting all on alphanumeric chars to _
$fileName = preg_replace('/\.*$/','',$fileName); // removing dot . after file extension

, foo&.pdf. foo.pdf

+3

, , ? - \& , , escape- unicode ( ;-)?

+1

, GET, script.php?file=this & that.mp3

, , . second: urlencode . char & %26.

script : script.php?file=this%20%26%20that.mp3 (%20 )

GET, that.mp3, . & GET


: ? phps unlink? exec rm ? ( ). , escapeshellarg. , (afaik, )

+1

- script? .

, glob() , ? ? , glob() _exists() ?

0

Source: https://habr.com/ru/post/1720366/


All Articles