Home > php教程 > php手册 > TP3.2使用UPYUN第三方存储

TP3.2使用UPYUN第三方存储

WBOY
Release: 2016-06-07 11:37:04
Original
1515 people have browsed it

封装UPYUN到TP,一个小的教程,相信很多朋友会用到,给大家分享一下
1.导入UPYUN类放到Vendor中,可以去UPYUN官网下载UPYUN类:
TP3.2使用UPYUN第三方存储
2.在UpyunUpload中加入你的BUCKET,如下private $option=array(<br>         'bucket'=>'你的空间名',/// 空间名<br>         'expiration'=> '',/// 授权过期时间<br>         'save-key'=>'/upload/{random}{.suffix}',/// 文件名生成格式,请参阅 API 文档<br>         'allow-file-type'=>'jpg,jpeg,gif,png',/// 控制文件上传的类型,可选<br>         'content-length-range'=>'0,1024000',///限制文件大小,可选 默认1M<br>         'image-width-range'=>'100,1024000',///限制文件宽度<br>         'image-height-range'=>'100,1024000',///限制文件高度<br>         //'return-url'=>'agent.html',//; /// 页面跳转型回调地址 !!! iframe 回调地址,注意客户网站上要部署 agent.html 进行跨域代理<br>         //'notify-url'=>'',<br>     );3.做完上面两步,现在我们去控制器里调用我们的UPYUN了
[b][/b] public function index(){<br>             vendor('Upyun.UpyunUpload');//实例化UPyun<br>             $option=array();<br>             //$option['bucket']='think-img-test';<br>             $option['expiration']=time()+3600;<br>           //<br>             $UpyunUpload=new \UpyunUpload($option);<br>             $this->assign('updata',$UpyunUpload->getData());<br>         $this->display();<br>     }4.由于我是使用UPLOADFIY插件,所以这里我就把我index.html的代码贴给大家了:nbsp;html><br> <br> <br> <meta> <br>   <script></script><br>     <script></script><br>     <link> <br> <br> <br>     <br>     <label>banner图</label><br><br>     <input><br>     <div></div> <br> <script><br /> $(function() {<br /> $(&#039;#file_upload3&#039;).uploadify({<br /> &#039;formData&#039; : {<br /> "policy":"<{$updata.policy}>",<br /> "signature":"<{$updata.sign}>",<br /> },<br /> &#039;fileSizeLimit&#039;:1024*1024,<br /> &#039;buttonText&#039;:&#039;请上传图片&#039;,<br /> &#039;swf&#039; : &#039;__PUBLIC__/Home/swf/uploadify.swf&#039;,<br /> &#039;uploader&#039; : &#039;http://v0.api.upyun.com/<{$updata.bucket}>/&#039;,<br /> &#039;onUploadSuccess&#039;:function(file,data,response){<br /> var result=eval(&#039;(&#039; + data + &#039;)&#039;);//将字符串当成JSON解析<br /> console.log(result);<br /> if(result.code==200){//这里请求成功之后UPYUN会返回给我们一个状态码,成功是200;<br /> //do something <br /> <br /> }<br /> }<br /> });<br /> });<br /> </script><br> <br> 5.到了这里已经是成功了的,我给大家截一下我成功的图:
TP3.2使用UPYUN第三方存储
6.成功啦!哈哈!你是不是很开森。。。。。

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template