Question:
I am trying to display images whose names contain accents.example of a filename:
Nestlé-Coffee-Mate-Original-Lite-311g.jpg
Originally I was displaying my images by accessing them directly from the public folder
Now I have got something like:
- Is there any way I can access files with accented names directly from the public folder without having to fetch via PHP because this slows the displaying of images a bit.
- And if I imperatively have to fetch via PHP because of the accents, what is the proper way to do it?
I have tried using
encodeURI
on the filename which resulted in something like:I have also tried various solutions from StackOverflow but none worked.
Answer:
There are two different representations of common accented characters in UTF-8, composed, and decomposed.- The composed representation uses a single codepoint,
é
\u00e9
\xC3\xA9
- The decomposed representation uses two codepoints, the base glyph
e
\u0065
\x65
and the combining mark for the accent\u0301
\xCC\x81
What you have posted in your question uses the latter, decomposed form. You may, in the short term, get your request to work by supplying the comosed form of that character.
That said, when accepting filenames with UTF-8 you should make a point of normalizing those names before writing them to disk, and/or creating links, to avoid this and other problems.
To normalize to Composed and Decomposed forms:
If you have better answer, please add a comment about this, thank you!