Pregunta

I've searched all over the web and didn't get the right answer for this, so the question is - is it even possible?

I am using the following code:

$file = $_POST['file_path'];
$content = $_POST['file_content'];
//get vars from post

$path = explode("/",$file);
$path_start = $path[0]."/".$path[1];
//define path_start

$i = 1;
while ($file != $path_start) {
if (!file_exists($path_start)) {
    mkdir($path_start,0777); 
}//end if
$i++;
$path_start = $path_start."/".$path[$i]; 
} //end while

if (isset($file) && isset($content)) {
    if (file_exists($file)) {
    unlink($file);
    } // file does not exist ... not anymore anyways
    $fp = fopen($file, 'w+');
    fwrite($fp,$content);
    fclose($fp);
    echo "The path is ".$file;
    } else {
    echo "Error!";
}

So the thing is $file contains the full path including name like:

.\comment\Folderč\Folderž\Folder\File22.txt

The code works fine, splits it to pieces but what the problem is... to create the folder with Folderč name. I simply cannot use any kind of replace characters function simply because all of the other files are depending on the variable already set (and thats a lot of files).

So is there any mkdir mode to create folder with special characters?

Thanks for feedback

¿Fue útil?

Solución

Try to use utf8-encode() like,

$file = utf8_encode($_POST['file_path']); // use utf8-encode here
$content = $_POST['file_content'];
//get vars from post

$path = explode("/",$file);
$path_start = utf8_encode($path[0]."/".$path[1]); // use utf8-encode here
//define path_start

$i = 1;
while ($file != $path_start) {
    if (!file_exists($path_start)) {
        mkdir($path_start,0777); 
    }//end if
    $i++;
    $path_start = utf8_encode($path_start."/".$path[$i]); // use utf8-encode here
} //end while

// your remaining code here
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top