0

I want to make a directory, but dir name conatains hurgarian characters. When I make one, look like this : Ă© instead of "é". How can i solve that problem?

Here is my code:

if( isset ( $_POST['submit'] ) )
    {
        foreach ($_FILES['files']['tmp_name'] as $key => $name_tmp) 
        {

            $name = $_FILES['files']['name'][$key];
            $allow = array('gif','jpg','png','JPG','jpeg');

            $ext = pathinfo($name, PATHINFO_EXTENSION);

            if(!in_array($ext, $allow))
            {
                echo "<div class='alert alert-danger text-center' role='alert'> The file is not an image! 
                </br><a class = 'btn btn-default' href = 'upload.php'> Back</a>
                </div>";
                exit();
            }
        }
        $album = $_POST['album'];
        $desc = $_POST['description'];
        $radio = $_POST['group'];
        $description = $_POST['description'];

        $query = "INSERT into albums values ('','$album','$radio','$desc')";
        $result = mysqli_query($db_connect,$query);

        $folder_name ='photos/'.$album.'/';

        if(!file_exists($folder_name))
        {   
            $new_dir = mkdir('photos/'.$album);
            $new_dir2 = mkdir('photos/new_'.$album);
        }   
        else
        {
            echo "<div class='alert alert-danger text-center' role='alert'> The album name is already exist! Please choose another 
                  </br><a class = 'btn btn-default' href = 'upload.php'> Back</a>
                  </div>";
            exit();
        }
  • did you check if your entire rendering pipeline is utf8-clean? Even a single stage ANYWHERE will cause that kind of corruption. html->form->browser->server->mysql connection->mysql table->etc... if there's ANY point in there where a different charset is used, you will get corrupted text. – Marc B Dec 15 '14 at 14:38
  • please check this [same question and answers][1]. [1]: http://stackoverflow.com/questions/1525830/how-do-i-use-filesystem-functions-in-php-using-utf-8-strings – berc Dec 15 '14 at 14:41
  • Yes! I checked all.If i echo the variable **$album** after submiting, its OK, i see the hungarian characters, and the coding is nice in mysql too... Just the created folder's name is bad. – Pinter Krisztian Dec 15 '14 at 14:43

1 Answers1

0

Your filesystem is not in UTF-8 encoding, but another one. If you are developing on Windows, it's likely Windows-1250. You need to convert it:

$folder_name = 'photos/' . iconv('utf-8', $config['filesystem_encoding'], $album) . '/';

where $config['filesystem_encoding'] = 'windows-1250'. Remember, your production server might use different encoding from your development server.

Marek
  • 7,337
  • 1
  • 22
  • 33
  • @PinterKrisztian I'm glad that helped. It's customary to accept the the right answer here ;) – Marek Dec 15 '14 at 15:57