File name with special characters like "é" NOT FOUND

I have a folder on my site for random files only. I used php opendir to list all the files in order to have a little pat on the page. But the files that I loaded with special characters in them do not work. when I click on them, it says no files were found. but when I check the directory, the files are there. the links seem to be wrong. Any idea how I can get the correct link to these file names with special characters in them?

+3
source share
2 answers

It's complicated. It depends on what encoding your file system uses for file names, and how (if) your web server or PHP functions convert the encoding.

First of all, make sure your links never use unencrypted non-ASCII characters. URLs must be in UTF-8, i.e. must be encoded as% C3% A9. If this does not work, try% E9 (é in ISO-8859-1).

You may find a function iconv()useful for converting encodings. rawurlencode()is a must.

+4
source

Do you see them if you run this?

foreach (new DirectoryIterator('/path/to/folder') as $fileInfo) {
    if($fileInfo->isDot() || $fileInfo->isDir()) continue;
    echo $fileInfo->getFilename() . "<br>\n";
}

EDIT: Just got it, I misunderstood the question. Probably something like a coding problem like porneL, says

0
source

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


All Articles