Question

I'am trying to upload a file named in arabic, after uploading the file saved in the db with it's arabic name correctly, but in the destination folder the file didn't saved with its correct name...so what is the problem here?

Was it helpful?

Solution

yes its windows

PHP, and other apps that use the MS C runtime's implementation of stdio file handling, cannot handle Windows filenames with characters outside the machine's default code page. If the server is set to Arabic you can upload Arabic (but then you can't upload Chinese or Latin accents). In theory you could set the process's code page to UTF-8 (65001) but there are serious bugs in the C runtime that make this unusably unreliable.

If you want Unicode filename support you would have to call the Win32 W APIs directly instead of relying on standard file IO, which is a lot of work unless the language has built-in support for it (.NET languages and Python do; PHP does not).

Allowing users to specify filenames to be used for server-side filesystem storage is dangerous and difficult to get right, especially under Windows. You are usually better off using surrogate filenames, eg 123.dat where 123 might be a database row ID. This also makes the Unicode problem go away. (You can use rewrites to make them appear to have friendlier names externally, if you want to serve them directly. Through IRI encoding, URLs can easily contain Unicode characters in the path.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top