1. Go to this page and download the library: Download mryup/filestore 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/ */
mryup / filestore example snippets
use Xxh\FileStore\Service\FileStoreAbstract;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
/**
* 文件管理
* @Inject
* @var FileStoreAbstract
*/
private $file;
//接收文件上传
public function filestore(RequestInterface $request, ResponseInterface $response)
{
$path = $this->file->store(
$request->file('img')
);
return $this->file->url($path);
//http://r-card.oss-cn-beijing.aliyuncs.com/tem/storage/4b7dd3231926a340ab84d53316f17e03.png
}
public function put()
{
$path = $this->file->put('1.txt','Hello World');
return $this->file->url($path);
//http://r-card.oss-cn-beijing.aliyuncs.com/tem/storage/1.txt
}
class OssFileStoreService extends Xxh\FileStore\Service\OssFileStoreService
{
//重写oss put方法
public function put($filename,$str)
{
.....
}
//新增oss delObject方法
public function delObject($filename)
{
$this->getClient()->deleteObjects($this->config['bucket'],$filename);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.