0

I use a Webserver for my Website. It has a MySql database with all the data and the Charset is set to UTF-8 so everything is correct on the Database side and also, on the Webserver i have some images with the name of the respective MySQL Content.
For example a field in MySql is Caffè and I also have an image called Caffè.jpg in another folder.

Now, i use PHP to build the page and i've already made sure that the content is interpreted as UTF-8 by doing this: header("Content-Type: text/html; charset=ISO-8859-1");
So take a look at this image:

enter image description here

As you can see, the HTML Page has the right name of the file: Caffè.jpg, but when the Browser asks for the image using GET, the è is not interpreted in the right way.
Could this mean that GET Requests don't accept those type of characters? This is how I get the name of the file:

<img src=\"./STRUCTURE/IMAGES/".$datas[$i]['name'].".jpg\" class=\"card_image\">

This might be useful. Thanks in advance.

Jasper Howard
  • 167
  • 1
  • 7
  • Does this answer your question? [unicode characters in image URL - 404](https://stackoverflow.com/questions/38978495/unicode-characters-in-image-url-404) – Michel Dec 19 '20 at 14:51
  • @Michel I read through the post and I understand why it's this way. But now the problem is how I can implement it, given that the only line I have is ``````. But thanks for your help. – Jasper Howard Dec 19 '20 at 14:58
  • 2
    "i've already made sure that the content is interpreted as UTF-8 by doing this: header("Content-Type: text/html; charset=ISO-8859-1?" — I beg your pardon? – Álvaro González Dec 19 '20 at 14:58
  • 1
    @ÁlvaroGonzález The PHP file is building the HTML page because it is getting all the necessary information from the database. Since I want the content to be interpreted as UTF-8, I added the line ```header("Content-Type: text/html; charset=ISO-8859-1)``` as the first line inside the PHP file. – Jasper Howard Dec 19 '20 at 15:00
  • 1
    If you want UTF-8, why do you declare ISO-8859-1? What role does ISO-8859-1 play here? It's like "To ensure it's interpreted as English, I've added language=French". – Álvaro González Dec 19 '20 at 15:02
  • @ÁlvaroGonzález from what I've read, writing ISO-8859-1 or UTF-8 is the same thing, I mean, they do the same thing. Without writing it, the ```è``` character was represented by a ```?```. – Jasper Howard Dec 19 '20 at 15:04
  • 1
    [ISO-8859-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) has less than 255 characters. [UTF-8](https://en.wikipedia.org/wiki/UTF-8) has the entire 143,859 character Unicode catalogue. Whatever article you've found stating that is seriously confused. – Álvaro González Dec 19 '20 at 15:09
  • @ÁlvaroGonzález I didn't knew that. But even if I just changed it to ```header("Content-Type: text/html; charset=utf-8)``` it still doesn't work – Jasper Howard Dec 19 '20 at 15:11
  • 1
    Have you been using ISO-8859-1 somewhere else? UTF-8 is everything you need to use as of 2020, but you need to use it all along the process. Also, `C3A8` is the correct UTF-8 encoding for `è`, that's completely right. – Álvaro González Dec 19 '20 at 15:15

1 Answers1

0

Links should be url-encoded, in your case: <img src=\"./STRUCTURE/IMAGES/".rawurlencode($datas[$i]['name']).".jpg\" class=\"card_image\">

If this won't work, try convert mysql data to UTF-8 before passing them to rawulrencode - you can do this using iconv or mb_convert_encoding

Your webserver should handle reverse translation.

Ref: https://www.w3schools.com/tags/ref_urlencode.ASP

TooMeeNoo
  • 56
  • 4
  • I've tried your solution and many others, I doesn't work at all. Interesting because on my local server it works very well, on the public one it doesn't. Do you need more details maybe to understand my situation? Thanks for your time anyways. – Jasper Howard Dec 19 '20 at 17:11
  • @JasperHoward When you say it this way, also your `GET` url `Caff%C3%A8.jpg` seems valid, then maybe we are looking for mistake in wrong place. For example, if your "Public" webserver uses Apache, the error may be here: [apache url / filename with special characters](https://serverfault.com/questions/449134/apache-url-filename-with-special-characters) So, maybe, check filename encoding on that server. – TooMeeNoo Dec 20 '20 at 18:25