PHP code example of lanqiukun / alioss
1. Go to this page and download the library: Download lanqiukun/alioss 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/ */
lanqiukun / alioss example snippets
namespace App\Http\Controllers;
use Lanqiukun\Alioss\Direct;
class TestCtrl extends Controller
{
static public function test()
{
//业务条件检查,例如权限是否满足,是否达到最大文件上传数量限制等。。。
$callback_url = env('APP_URL') . '/api/test_callback'; //设置oss上传成功的回调,回调返回的内容将原封不动地返回客户端
$dir = 'qwer/asdf'; //限制客户端只能将文件上传到oss的qwer/asdf目录下
$max_body_size = 2000; //限制客户端最大上传文件大小2000KB
return Direct::sign_policy($callback_url, $dir, $max_body_size);
}
static public function test_callback()
{
//客户端上传的文件的信息
$fileinfo = request()->all();
//根据以下请求参数验证签名
$public_key = file_get_contents(base64_decode($_SERVER['HTTP_X_OSS_PUB_KEY_URL']));
$body = file_get_contents('php://input');
$path = $_SERVER['REQUEST_URI'];
//阿里云oss服务器会将此处返回的信息原封不动地返回给上传文件的客户端
return Direct::callback($fileinfo, $public_key, $body, $path);
}
}