PHP code example of ijin82 / flysystem-azure

1. Go to this page and download the library: Download ijin82/flysystem-azure 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-azure example snippets


public function someUploadFuncName(Request $request)
{
    $file = $request->file('file_name_from_request');  
    
    // .. file name logic
    // .. file folder logic
    
    $file->storeAs($fileFolder, $fileName, [
        'disk' => 'my_azure_disk1'
    ]);  
    
    // save file name logic
    // to create file URL by name later
    // maybe you want to save file name and folder separated
    $fileNameToSave = $folderName . '/' . $diskFileName;
    
    // .. save file name to DB or etc.
}

echo Storage::disk('my_azure_disk1')->url($fileName);

public function someDeleteFuncName($id)
{
    $file = SomeFileModel::findOrFail($id);
    Storage::disk('my_azure_disk1')->delete($file->name);
    $file->delete();

    // go back or etc..
}

$fileConents = Storage::disk('public_or_another_local_disk')->get($file);

$forcedMimes = [
    'js' => 'application/javascript',
    'json' => 'application/json',
];

$fileExt = \File::extension($file);

if (array_key_exists($fileExt, $forcedMimes)) {
    $fileMime = $forcedMimes[$fileExt];
} else {
    $fileMime = mime_content_type(Storage::disk('public_or_another_local_disk')->path($file));
}

Storage::disk('my_custom_azure_disk')->put($fileName, $fileConents, [
    'mimetype' => $fileMime,
]);