Trying to organize multi-uploading files to the server, I encountered the problem that Russian-language file names are saved as a broken encoding (i.e., letters are replaced with hieroglyphs), tried to implement the transliteration of Russian-language names, but the function I wrote cannot translate, tell me, please, what There may be a problem.
HTML code for the page:
<html><head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="script.js"></script> <body> <form name="upload" action="upload.php" method="post" enctype="multipart/form-data"> <div id="files"> <input name="file[]" type="file" value="" class="1" onChange="make_input(this);"> <input type="submit" value="Загрузить" > </div> </form> </body>
JS script code:
function make_input(el) { if ($(el).attr("class") == 1) { $('<input name="file[]" type="file" value="" class="1" onchange="make_input(this);"><br>').prependTo("#files"); $(el).attr("class", "2"); } };
Upload.php form handler code:
<?php include("1.php"); $uploaddir=";"; $count_file=is_array($_FILES['file']['name'])?count($_FILES['file']['name']):0; if($count_file>0) { for($i=0;$i<$count_file;$i++) { if($_FILES['file']['error'][$i]==0) { transl($_FILES['file']['name'][$i]); $name_file=basename($_FILES['file']['name'][$i]); $uploadfile = $uploaddir.$name_file; if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $uploadfile)) { $file_upload['file_upload'][]=$_FILES['file']['name'][$i]; } else { $file_upload['error'][]=$_FILES['file']['name'][$i]; } } } } echo "<ul>Файлы загружены :"; if(is_array($file_upload['file_upload'])) foreach($file_upload['file_upload'] as $var) { echo "<li>{$var}</li>"; } echo "</ul>"; echo "<ul>Файлы не загружены :"; if(is_array($file_upload['error'])) foreach($file_upload['error'] as $var) { echo "<li>{$var}</li>"; } echo "</ul>"; echo ($file_upload); ?>
And the actual code of the file with the translate function 1.php:
<?php function transl($text) { $trans = array( "а" => "a", "б" => "b", "в" => "v", "г" => "g", "д" => "d", "е" => "e", "ё" => "e", "ж" => "zh", "з" => "z", "и" => "i", "й" => "y", "к" => "k", "л" => "l", "м" => "m", "н" => "n", "о" => "o", "п" => "p", "р" => "r", "с" => "s", "т" => "t", "у" => "u", "ф" => "f", "х" => "kh", "ц" => "ts", "ч" => "ch", "ш" => "sh", "щ" => "shch", "ы" => "y", "э" => "e", "ю" => "yu", "я" => "ya", "А" => "A", "Б" => "B", "В" => "V", "Г" => "G", "Д" => "D", "Е" => "E", "Ё" => "E", "Ж" => "Zh", "З" => "Z", "И" => "I", "Й" => "Y", "К" => "K", "Л" => "L", "М" => "M", "Н" => "N", "О" => "O", "П" => "P", "Р" => "R", "С" => "S", "Т" => "T", "У" => "U", "Ф" => "F", "Х" => "Kh", "Ц" => "Ts", "Ч" => "Ch", "Ш" => "Sh", "Щ" => "Shch", "Ы" => "Y", "Э" => "E", "Ю" => "Yu", "Я" => "Ya", "Ъ" => "", "ъ" => "", "ь" => "", "Ь" => "" ); if(preg_match("/[А-Яа-яa-zA-Z\.]/", $text)) { return strtr($text, $trans); } else { return $text; }; } ?>
Thank! I would be very happy with any help.