PHP code example of janfish / storage

1. Go to this page and download the library: Download janfish/storage 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/ */

    

janfish / storage example snippets


$di->set('cloudStorage', function () use ($config) {
    return new CloudStorage([
        'version' => 'GridFs',
        'api' => 'http://disk.xy.cn/',
        'imagePrefix' => 'http://cdn.xy.cn/',
        'tag' => 'insurance',
        'appId' => 'test',
        'appSecret' => 'test123456',
    ]);
});

$cloudStorage = $app->cloudStorage;
if ($cloudStorage->remove(['insurance/201928/106785628.jpeg','insurance/201928/2332727541.jpeg']) === false) {
    echo  $cloudStorage->getError();
}

echo $app->cloudStorage->getStaticUrl('insurance/201928/2332727541.jpeg');

echo $app->cloudStorage->getStaticUrl('insurance/201928/2332727541.jpeg',['width'=>100,'height'=>100,clipType='1']);

$result = $cloudStorage->setFile($_FILES[0]['tmp_name'])->upload();
if ($result === false) {
    return $app->apiResponse->error($cloudStorage->getError());
}
$images = $cloudStorage->getResult();

$result = $cloudStorage->setFile($_FILES[0]['tmp_name'],'.jpg)->upload();
if ($result === false) {
    return $app->apiResponse->error($cloudStorage->getError());
}
$images = $cloudStorage->getResult();

$result = $cloudStorage->setFile($_FILES[0]['tmp_name'])->setTag('test')->upload();
if ($result === false) {
    return $app->apiResponse->error($cloudStorage->getError());
}
$images = $cloudStorage->getResult();

$cloudStorage = $app->cloudStorage;
$files = array_column($_FILES, 'tmp_name');
$cloudStorage->setFiles($files);
$cloudStorage->setTag('insurance');
if ($cloudStorage->upload() === false) {
    echo $cloudStorage->getError();
}
$images = $cloudStorage->getResult();

$result = $app->cloudStorage->setAllowed([
     'image/jpeg',
     'image/jpg',
     'image/png',
     'application/zip',
     'application/x-rar',
     'application/x-zip-compressed',
 ])
 ->setMaxSize(5)
 ->setFiles(array_column($_FILES, 'tmp_name'))
 ->setTag('insurance')->upload();
if ($result === false) {
   echo $app->cloudStorage->getError()
}