简体   繁体   中英

Laravel charset - utf8

I'm using Laravel 5 and i'm making an AJAX request with which the user can create a directory . But if the user uses a Cyrillic alphabet the newly created dir appears to be strange: РЎРЅРёРјРєРё . This is the ajax:

$.ajax({
       async: true,                      
       method: 'POST',
       dataType: 'json',
       url: '../public/createfolder',
       data: {foldername: $('#folder-name').val(), "_token": csrf},
       complete: function(response) {
           console.log(response);                  
       }
});

And that's how I catch the request:

public function createFolder(){
        $foldername = $_POST['foldername'];
        $ds = DIRECTORY_SEPARATOR;
        $userid = Auth::id();
        Storage::disk('local')-> makeDirectory('uploads'.$ds.$userid.$ds.$foldername);
    }

How can this be avoided?

I suppose your directory names are stored in the database. In this case, you can just create the actual directories with the name as their id in the database.

Also you don't really have to create a directory, even if the user thinks he's creating it. Unless you allow the user to access it through FTP, there's no need to create it. You can have a single directory for each user and assign the files in the database to a virtual directory, that's only displayed to the user, even though the files are all in the same location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM