1

I want to change the name of uploaded file but the name which I want to change is in Persian

this is my php code

   $imageType= explode("/",$_FILES["photo"]["type"]);
   move_uploaded_file($_FILES["photo"]  ["tmp_name"],"images/staff_photos/".$name."_".$fatherName."_".$lname.".".$imageType[1]);

($name, $fatherName, $lname)are the variables which contain Persian string values in echoing or print_r it shows the right name but the output file name is like this:

" مصطÙÛŒ_عبدالعزیز_علومی.jpeg " so How can I change the charset in utf-8

MAO
  • 81
  • 9
  • What do you mean by "the output file name"? – arkascha Nov 30 '15 at 20:21
  • The name of the file which I move to that specific folder – MAO Nov 30 '15 at 20:23
  • you can review this http://stackoverflow.com/questions/18204364/php-upload-utf-8-filename – Gouda Elalfy Nov 30 '15 at 20:47
  • So the file stored on the server side has the unexpected name? OK, in that case the question is where those characters come from. You do not post that part of your code, so it is unclear in what encoding your script actually works. If browser and server communicate in some other encoding than unicode, often an 8bit based, then there is no good way you can change that afterwards. Take care to solve the issue, not the symptom. And the issue here apparently is that you do _not_ have a unicode environment, but some mix. That will again and again cause issues. You have to solve that. – arkascha Dec 01 '15 at 07:29
  • @MAO Updated my answer – SamyQc Jan 12 '16 at 21:27

1 Answers1

0
Try changing the header before outputting the file.
<?php 

    header('Content-type: text/plain; charset=utf-8'); 

?>

EDIT :

(windows-1256 is a code page used to write Arabic like persian language)

$imageType= explode("/",$_FILES["photo"]["type"]);
$filename = $name."_".$fatherName."_".$lname.".".$imageType[1];
$filename = iconv("utf-8", "windows-1256", $filename);
move_uploaded_file($_FILES["photo"]  ["tmp_name"],"images/staff_photos/".$filename;

EDIT 2 :

Also, be sure to have the Windows Language Pack installed for Persian Language : Microsoft Language Pack Download Center

SamyQc
  • 365
  • 2
  • 10
  • Where should I put this exactly I put it before move_uploaded_file but by submitting it shows me the html code or something like that – MAO Nov 30 '15 at 20:30
  • Didn't work still it shows me the html code after submitting the form – MAO Nov 30 '15 at 20:53
  • Did you remove the '' header('Content-type: text/plain; charset=utf-8'); '' ? If not, remove it and try what I wrote in my edit – SamyQc Nov 30 '15 at 20:58
  • Thanks but now I am facing this error Notice: iconv(): Wrong charset, conversion from `utf-8' to `cp1256 ' is not allowed in C:\wamp\www\Archive\newVersion\forms.php – MAO Nov 30 '15 at 21:34
  • Try to change cp1256 for windows-1256 – SamyQc Nov 30 '15 at 21:41
  • again the same error even I changed the position of cp1256 and UTF8 the error disappeared but the name of the file is change to something like this ط؛إ’ط·آ³ط·آ¨ط·آ³ط؛إ’ط·آ¨ط·آ³__.jpeg – MAO Nov 30 '15 at 22:04
  • Mmmm, no luck then .. You could try that : open a ''cmd'' on your Windows, and run the command ''chcp''. It should give you a code page number. Change the cp1256 for the code page number that the command give you. – SamyQc Dec 01 '15 at 13:18
  • You should install the appropriate language pack for the persian language on your Windows: http://windows.microsoft.com/en-us/windows/language-packs#lptabs=win81 – SamyQc Jan 06 '16 at 16:37