1

I am scanning a directory through PHP5's RecursiveIteratorIterator smoothly. But it returns some file names as �esmi.jpg as represents 'Ç' actually. That's why I can't rename file name simply because php cannot access the file. How can I proceed? Thanks for any hint.

YahyaE
  • 1,057
  • 1
  • 9
  • 24
  • The encoding of the filename shouldn't matter if you are not displaying it. What happens if you try to rename it? – laurent Jul 07 '13 at 15:26
  • @Laurent "No such file or directory" returns while i can change other file names correctly with the same code. – YahyaE Jul 07 '13 at 15:28
  • 1
    You need to convert those characters into UTF8 or whatever charset your filesystem uses. – mario Jul 07 '13 at 15:29
  • @mario I am running on Win7 Professional/XAMPP. So you mean it runs on Linux systems but not in Windows systems? – YahyaE Jul 07 '13 at 15:30
  • See also [How do I use filesystem functions in PHP, using UTF-8 strings?](http://stackoverflow.com/q/1525830) – mario Jul 07 '13 at 15:35
  • you could try using the `utf8_decode()` function when searching for the file and then `utf8_encode()` when renaming it. also, if you are echoing out the filenames through a browser make sure you set the HTML tag `` in the `` so as to display the characters correctly – pulsar Jul 07 '13 at 15:38
  • 1
    Why does everyone assume that the file system is encoded in utf? That is a MS-Windows system, so medieval technology! I'd say: first of all find out what encoding that file system really uses. Then adjust your php configuration accordingly or convert in an explicit manner. – arkascha Jul 07 '13 at 15:40
  • @verbumSapienti it's not working. – YahyaE Jul 07 '13 at 16:07
  • @arkascha `iconv("Windows-1254" , "UTF-8", $file)` does the job but `Ç` is corrected but `İ` characters are assumed as `I` so still can't access the file. – YahyaE Jul 07 '13 at 16:09
  • So I'd say: aparently this does _not_ do the job, it only does _something_. How did you detect the encoding your file system uses? – arkascha Jul 07 '13 at 16:11
  • @arkascha You're right. I use Win7 US English, so it should be UTF-8. The problem here PHP5 iterator (I noticed now) returns array by changing `İ` to `I` and `ı` to `i`. If I can stop it will works. I mean `Çeşmi SİYAHım.jpg` comes to files array as `files/�esmi SIYAHim.jpg` – YahyaE Jul 07 '13 at 16:25
  • MS-Windows systems use different encodings for their file systems depending on a number of points. So you cannot be sure your system does use UTF-8 encoding if you do not check it. The php iterator extension certainly works correct with utf-8 as input, so there must be some other issue. I suggest you dump the information into files at different points during the processing stages and compare the dumps using a hexeditor. This is the only reliable way to really see what characters/encodings are actually used. – arkascha Jul 07 '13 at 16:30
  • I'll try my best to determine it, thank you fy help and time. – YahyaE Jul 07 '13 at 16:44

0 Answers0