0

I've built a Website that uses a MySQL database and it works correctly on my Localhost using xamp. But, when I copy the exact files(including the Database) using Filezilla on the Web Server, the files that are named with an accent, in my case the file named Caffè.jpg can't be found for some reason.

Basically, the database contains the name of the files so if I have a record called Juices inside the database, then PHP is going to build the website and it's going to take the file named Juices.jpg from the storage. Even on the Web Server, all the other files work great, but only the words with an accent are not working correctly. I get this error on the Web Server:

GET http://www.website.com/STRUCTURE/IMAGES/Caff%EF%BF%BD.jpg 404 (Not Found)

I know that the error might come from the fact that the Database on the Web Server uses a different encoding than on Localhost but I don't think that's the cause. Take a look at this image: enter image description here

To get the images on the page, I wrote this line: <img src=\"./STRUCTURE/IMAGES/".$datas[$i]['name'].".jpg\" class=\"card_image\">

As you can see I made sure to use the same encoding on both Databases and in the index.php file I even added the line <meta charset="utf-8"/>. I tried all the solution I could think of and found online but with no result. In case it might be useful, I use Aruba.it for my Web Server. In case you need more details I can easily modify the post. Thank You in advance!

Jasper Howard
  • 167
  • 1
  • 7
  • See "black diamond" in https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Dec 22 '20 at 18:39

1 Answers1

0

Be sure your MySQL server has utf8mb4 connection

SHOW VARIABLES LIKE 'collation%';
SHOW VARIABLES LIKE 'character%';

Edit MySQL config (/etc/my.cnf) something like this

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

[mysqld]
character-set-server=utf8mb4
init-connect='SET NAMES utf8mb4;'
collation-server=utf8mb4_general_ci

Restart MySQL server

service mysqld restart
miniman
  • 61
  • 3
  • Thank you. So, I tried the first two queries and the result is: ```collation_connection->utf8mb4_general_ci collation_database->utf8mb4_general_ci collation_server->latin1_swedish_ci``` and it still doesn't work. I have to say that I don't have access to the my.cnf file for now, only to the GUI of the Database and also the server collation is in latin_swedish, I don't know what to do. – Jasper Howard Dec 21 '20 at 19:05
  • Do you have root access in phpMyAdmin? Which results for second query? SHOW VARIABLES LIKE 'character%'; – miniman Dec 21 '20 at 20:35