file name with special characters like “é” NOT FOU

2019-05-10 23:19发布

I have a folder on my website just for random files. I used php opendir to list all the files so i can style the page a bit. But the files that I uploaded with special characters in them don't work. when i click on them it says the files are not found. but when i check the directory, the files are there. seems like the links are wrong. any idea how i can get a correct link to these file names with special characters in them?

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-05-10 23:59

This is tricky. It depends what encoding your filesystem uses for filenames and how (if) your webserver or PHP functions convert the encoding.

First of all, make sure your links never use unencoded non-ASCII characters. URLs should be in UTF-8, i.e. é should be encoded as %C3%A9. If that doesn't work, try %E9 (é in ISO-8859-1).

You might find iconv() function useful to convert encodings. rawurlencode() is obligatory.

查看更多
时光不老,我们不散
3楼-- · 2019-05-11 00:12

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 realised i misread the question. Its likely some kind of encoding issue like porneL says

查看更多
登录 后发表回答