proner/storage

v0.1.13 2020-09-17 14:14 UTC

README

PHP 客户端用于与存储通信

安装

composer require proner/storage

示例

<?php
use Proner\Storage\Storage;
$storage = new Storage('ftp');
$storage->setHost('172.20.15.999');
$storage->setLogin('usuario','senha');

$storage->setWorkdirLocal('arquivos');
$storage->setWorkdirRemote('arquivos');

//conectar e habilitar o cache
$storage->cacheConnect('172.20.15.990', 6379);

可以使用库的 门面(静态方法),但需要设置好环境变量。

方法

方法: get

从服务器下载文件

<?php
$file = 'pasta/teste.txt'; //Arquivo que vai ser baixado
$path = 'pasta'; //Diretorio a onde o arquivo será salvo locamente

$storage->get($file, $path);

//OU COM MÉTODO ESTATICO

Storage::get($file, $path);

方法: getContent

获取服务器上文件的文件内容

<?php
$file = 'pasta/teste.txt'; //Arquivo que está procurando

$storage->getContent($file);

//OU COM MÉTODO ESTATICO

Storage::getContent($file);

方法: put

将文件发送到服务器

<?php
$file = 'pasta/teste.txt'; //Arquivo que vai ser enviado
$path = 'pasta'; //Diretorio a onde o arquivo será salvo locamente

$storage->put($file, $path);

//OU COM MÉTODO ESTATICO

Storage::put($file, $path);

方法: putContent

在服务器上创建文件

<?php
$file = 'pasta/teste.txt'; //Arquivo que vai ser enviado
$content = 'pasta'; //Conteúdo do novo arquivo

$storage->putContent($file, $content);

//OU COM MÉTODO ESTATICO

Storage::putContent($file, $content);

方法: fileExists

在指定目录中定位文件

<?php
$file = 'teste.txt'; //Arquivo que está procurando
$path = 'pasta'; //Diretorio que está procurando o arquivo

$storage->fileExists($file, $path);

//OU COM MÉTODO ESTATICO

Storage::fileExists($file, $path);

方法: getImage

返回图像内容的 base64,适用于 HTML

<?php
$file = 'teste.jpg'; //Imagem

$storage->getImage($file); // data:image/jpg;base64, /9j/4AA.....

//OU COM MÉTODO ESTATICO

Storage::getImage($file); // data:image/jpg;base64, /9j/4AA.....

环境变量

//CONEXAO
PSTORAGE_DRIVER //Define o driver(ftp default)
PSTORAGE_HOST //Define o host da conexao
PSTORAGE_USER //Define o usuario da conexao com o host
PSTORAGE_PASS //Define a senha da conexao com o host
PSTORAGE_WORKDIR_LOCAL //Define o diretorio local a onde todas as ações serão execultadas por padrão.
PSTORAGE_WORKDIR_REMOTE //Define o diretorio remoto a onde todas as ações serão execultadas por padrão.

//CACHE
PSTORAGE_CACHE //Habilita o cache (true ou false)
PSTORAGE_CACHE_HOST //Define o host do serviço de cache
PSTORAGE_CACHE_PORT //Define a porta do serviço de cache;
PSTORAGE_CACHE_SECURITY //Habilita conexão segura com o serviço de cache
PSTORAGE_CACHE_LOGIN //Define a senha do serviço de cache;
PSTORAGE_CACHE_PASSWORD //Define a senha do serviço de cache
PSTORAGE_CACHE_TTL //Define o tempo de vida do cache