1、在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现Web端直传,服务端签名直传并设置上传回调,前提是先参照:http://www.shuijingwanwq.com/2016/01/13/909/ 实现,设置Bucekt(storage4-hmwis-com)的CORS,如图0;
2、查看帮助文档Web端直传实践——服务端签名直传并设置上传回调,下载代码示例,应用服务器返回签名代码:oss-h5-upload-js-php-callback.tar.gz、回调应用服务器版本:callback-php-demo.zip,如图1、2
3、复制:E:/wwwroot/oss-h5-upload-js-php-callback/php/get.php中的function gmt_iso8601至E:/wwwroot/ke.hmwis.com/Application/Common/Common/function.php,如图3
4、打开:E:/wwwroot/ke.hmwis.com/Application/Home/Controller/FileController.class.php,新建上传表单的方法,如图4
/* 文件上传表单,基于OSS,web直传 */
public function ossUpload(){
$this->display();
}
5、打开:E:/wwwroot/oss-h5-upload-js-php/index.html,复制全部内容至:E:/wwwroot/ke.hmwis.com/Application/Home/View/default/File/ossUpload.html,且调整其中的相应文件路径,如图5
6、打开:http://ke.ygt.cm/File/ossUpload.html ,查看网页源代码,如图6
7、复制E:/wwwroot/oss-h5-upload-js-php-callback下的相应文件至:E:/wwwroot/static.hmwis.com/ke/Public/static/oss目录,如图7
8、打开:E:/wwwroot/oss-h5-upload-js-php-callback/php/get.php,导入OSS的客户端类、异常类,如图8
use OSS/OssClient;
use OSS/Core/OssException;
9、打开:E:/wwwroot/oss-h5-upload-js-php-callback/php/get.php,复制除function gmt_iso8601之外的所有代码至:E:/wwwroot/ke.hmwis.com/Application/Home/Controller/FileController.class.php下的public function ossGet(),且实例化OSS2.0.4的客户端类,如图9
10、配置zhidao.ygt.cm的虚拟主机:
* 注意:如果要使用HTTP_AUTHORIZATION头,你需要先在apache或者nginx中设置rewrite,以apache为例,修改
* 配置文件/etc/httpd/conf/httpd.conf(以你的apache安装路径为准),如图10
添加一行:
RewriteRule .* – [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
11、编辑:E:/wwwroot/static.hmwis.com/ke/Public/static/oss/upload.js,如图11
phpUrl = ‘http://ke.ygt.cm/File/ossGet.html’
12、编辑:E:/wwwroot/oss-h5-upload-js-php-callback/callback.php,如图12
file_put_contents(‘./data/1.txt’, json_encode($body));
13、测试上传成功,如图13、14
14、测试回调成功,查看zhidao.ygt.cm/data/1.txt,如图15
“filename=user-dir%2F10.png&size=218185&mimeType=image%2Fpng&height=453&width=674”
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/180184.html