• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: PHP – readfile on accented filenames

Resolved: PHP – readfile on accented filenames

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

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
But only images without accents was displaying and I had to switch to fetching the images via my backend (PHP)
Now I have got something like:
PHP code:
  1. 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.
  2. 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:
and in PHP:
but none of the above worked.
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:
Output:
You should also check how your OS and filesystem handle UTF-8 filenames. Some will simply write any series of bytes as the filename, some will be picky and reject, and others will perform their own normalization that may not neccessarily match what you have chosen in your app.

If you have better answer, please add a comment about this, thank you!

html php
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: In Bigquery How iterate the records as per counter in the table

27/03/2023

Resolved: Java Swing center JLabel in JPanel with two JLabels

27/03/2023

Resolved: How to compare two text files and and change the sign of the data in powershell?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.