PHP Classes

File: examples/02-downloading-file.php

Recommend this page to a friend!
  Classes of Alexandre Sinício   PHP Cloud Storage Abstraction   examples/02-downloading-file.php   Download  
File: examples/02-downloading-file.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Cloud Storage Abstraction
Store and retrieve data in multiple cloud services
Author: By
Last change:
Date: 6 years ago
Size: 896 bytes
 

Contents

Class file image Download
<?php
use SinFramework\Storage\LocalStorage;

require
'../bootstrap.php';
require
'../vendor/autoload.php';

//OUR GLOBAL VARS FOR THIS EXAMPLE
$file = 'demo.txt';
$fileID = '1234567890_1234567890';
$bucket = 'mybucket';

//GET STORAGE OBJECT
$storage = getStorageObj();

//DOWNLOAD FILE
try {
   
$storage->getFile($fileID, $file, $bucket);
    exit;
//DOWNLOAD SHOULD BE LAST ACTION PERFORMED ON SCRIPT, SO WE FORCEFULLY EXIT ON THIS EXAMPLE
} catch (Exception $e) {
    die(
$e->getMessage());
}

//THIS FUNCTION IS RESPONSIBLE FOR CREATING AND SETTING UP THE STORAGE OBJECT
//IN A REAL WORLD APPLICATION, IT SHOULD BE CONTAINED IN SOME KIND OF DEPENDENCY INJECTOR CONTAINER
/**
 * @return \SinFramework\Storage\StorageInterface
 */
function getStorageObj() {
   
$storageObj = new LocalStorage();
   
$storageObj::setBaseStorageLocation('../storage');
   
    return
$storageObj;
}