i have a problem with upload files with greek names {μανος.jpg} uploaded with Ξ Ξ΅ΞΤΥΠΞ.jpg on my directory why?I do not use mysql, the others image uploaded success with their own name.
my code is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.or开发者_如何学Pythong/1999/xhtml" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
$uploaddir = './uploads/';
$file = $uploaddir . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
echo "success";
} else {
echo "error";
}
?>
</head>
<body>
</body>
THANKS
It seems that the underlying file system can't deal with unicode file names, or is getting incorrect data from the browser.
Make sure the form you send the file with is also UTF-8 encoded.
If that does not help:
The most common way to go about it is to give the file a new, computer-generated name (like a number, or the user's ID and a serial number, or a random string). This would be the easiest way.
If that is not an option, try using
urlencode()
on the file name before storing it. That will create a file name that is guaranteed to work on the file system. Whenever outputting the file name, useurldecode()
to display it - if it's not the browser who got the encoding wrong, this should show proper greek characters.If that doesn't work, the browser is sending the file name in the client operating system's encoding (e.g. UTF-16 in Windows/NTFS). In that case, you would either need to start sniffing the character encoding (which is terribly unreliable) or go with option 1.
The character encoding your operating system guesses the filename is in, is not the same as the character encoding that's used to upload the file.
What these character encodings are, is highly dependant on the browser used.
You probably need to use iconv()
to convert the submitted filename into the same character encoding as is expected by your filesystem.
Alternately if you don't care how it looks on the disk but just want to display it back in a different page call, consider doing something like base64 encoding the filename. Using international characters in filenames is something which eventually causes me problems every time I've tried.
精彩评论