简体   繁体   中英

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: http://www.med4u.gr/timokatalogoi/ This is the directory listing: http://www.med4u.gr/pricelists/

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: add header('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 the head .
  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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM