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/ */
# Get file URL example
$publicUrl = Storage::disk('disk1')->url('file-folder/file1.png');
# Check file exists example
$exists1 = Storage::disk('disk1')->exists('file-folder/file1.png');
# Get file contents example
$contents = Storage::disk('disk1')->get('file-folder/file1.png');
# Delete file example
Storage::disk('disk1')->delete('file-folder/file1.png');
# Delete directory example
# Warning, recursive folder deletion!
Storage::disk('disk1')->deleteDir('file-folder');
# Put uploaded file to storage example
# $file could be file path on disk (string) OR type of File|UploadedFile
Storage::disk('disk1')->putFileAs('file-folder', $file, 'file1.png');
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.
}
public function someDeleteFuncName($id)
{
$file = SomeFileModel::findOrFail($id);
Storage::disk('my_azure_disk1')->delete($file->name);
$file->delete();
// go back or etc..
}