PHP code example of ijin82 / flysystem-webdav

1. Go to this page and download the library: Download ijin82/flysystem-webdav library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ijin82 / flysystem-webdav example snippets


return [
    //...
    'providers' => [
        //...
        Ijin82\Flysystem\Webdav\WebdavServiceProvider::class,
        //...
    ],
    //...
];

return [
    //...
    'avatars' => [
        'driver' => 'webdav',
        'baseUri' => 'http://host.name.com',
        'path_prefix' => 'avatar/',
        'path_alias' => '',
        'userName' => 'webdav_user_login',
        'password' => 'webdav_user_password',
    ],
    //...
];

public function avatarUpload(Request $request)
{
    //...
    $file = $request->file('avatar_file');
    //... check file type, build name, save name in DB, whatever you like
    $fileName = $file->getClientOriginalName(); // for example
    // https://laravel.com/docs/5.5/requests#storing-uploaded-files
    $file->storeAs('subfolder-name-or-empty', $fileName, ['disk' => 'avatars']);
    //...
    // save file name or logic to build that
    //...
}

//... fileName logic
$fileUrl = Storage::disk('avatars')->url($fileName);

Storage::disk('avatars')->delete($fileName);

// WARNING, all files inside that also will be deleted
Storage::disk('avatars')->deleteDir('dir-name/or/path');