How do I upload a php file correctly, when it has special characters or accents?

0
Hello, I'm trying to upload an audio file in php, the problem is that the file should be moved to a name with accent, til, for example. Example: Except the file with name of Sebastião.mp3, but the php at the time of moving the upload of the file moves with the name of Sebastião.mp3

look at the file upload.php

$target_dir = "../../mp3/";
$nomeF="Sebastião"; <- aqui eu pego no banco de dados o nome...
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file2=utf8_encode($target_dir).$nomeF.utf8_encode(".mp3"); <- tentei codificar o arquivo mas nao deu resultado
ou
$target_file2=$target_dir.$nomeF.".mp3";
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if ($_FILES["fileToUpload"]["size"] > 59900000) {
        $uploadOk = 0;
    }
    // Allow certain file formats
    if($imageFileType != "mp3" ) {
        $uploadOk = 0;
    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {

    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file2)) {

        } else {

        }
    }

However, as I said, the file saved wrong. Does anyone know what to do?

    
asked by anonymous 18.12.2018 / 00:57

1 answer

0

An interesting approach is to create a hash using MD5 to be the name of the file in your directory and save it in the bank linking to the real name (with accents and special characters)

echo md5('apple');
//1f3870be274f6c49b3e31a0c6728957f

I see it as a secure and organized way.

    
18.12.2018 / 02:16