php - utf8 filenames and greek chars


I'm trying to figure this out but I'm quite puzzled at the mo. I have a directory in my website containing pdf files with greek filenames (ie ΤΙΜΟΚΑΤΑΛΟΓΟΣ.pdf) I want to have links for the files on a web page so that users can open or save the files. So far I can list the files ok but if I click on them I get a 404 error. It's as if the server thinks they're not there although they are. I understand it's problably an encoding issue but beyond that I'm not sure what to look for. The website encoding is utf-8 and in order to display the filenames correctly I had to use mb_convert_encoding($file->filename, 'utf8', 'iso-8859-7').

This is the url: This is the directory listing:

The site is based on Joomla and it's hosted on a linux server.

Any ideas?




ISO-8859-* MUST DIE! (That's not personal!) Do everything in UTF-8. Everything. With good reason, some of us get upset when we see them being used, especially Latin-1 (8859-1) which bites a lot of people. I think you would find it very helpful to just dump them and move on to UTF-8.

Things to check:

  1. Store your files encoded in UTF-8: Usually no difficulties with that.
  2. Make sure your server is sending the files with UTF-8 charset: addheader('Content-Type: text/html;charset=UTF-8'); near the top of your PHP.
  3. Just in case someone saves your page, it's helpful in that case to put the same thing in a<meta> tag in thehead.
  4. Check it all in your browser: right click, view page info, and make sure the encoding is right.

CPanel is very flexible, so that's all doable without much fuss. Feel free to comment if you want more detail.

If you have a database, there are a few more hoops to jump through, but it's worth it. With UTF-8 you never have to worry, and it's the definitive, future-proof way of doing things.




Let's suppose for the sake of argument that the file name on disk is aa.pdf but your conversion displays it as ab.pdf. You need either to revert the conversion so it points back to aa.pdf, or teach the server to remap or redirect requests for ab.pdf to this file. Or if you prefer, rename the file to ab.pdf instead, if your file system can handle this name.




It's definitely an encoding problem. You'll need to escape the URL, or convert it to whatever character set your server recognises.

e.g. 'ΤΙΜΟΚΑΤΑΛΟΓΟΣ LASER.pdf' in iso-8859-7 = 'ÔÉÌÏÊÁÔÁËÏÃÏÓ LASER.pdf' in iso-8859-1

People are also looking for solutions to the problem: php - How to make FB Recommend button clickable more than once?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.