Thinkphp3.2.3一则使用又拍云驱动上传文件的实现,分享给需要集成又拍云文件上传的小伙伴们。
首先在项目任意的配置文件加入如下配置:
'FILE_UPLOAD_TYPE' => 'Upyun',
'UPLOAD_TYPE_CONFIG' => array(
//又拍云host,默认即可
'host' => 'v0.api.upyun.com',
//又拍云创建的空间名
'bucket' => '',
//对应空间的操作员名称
'username' => '',
//操作员口令
'password' => ''
),
controller实现:
namespace Home\Controller;
use Think\Upload;
class UploadController extends Controller {
public function uploadImage(){
$upload = new Upload(); //文件上传对象实例化
$upload->rootPath = './'; //根目录,默认./即可
$upload->savePath = 'avatar/'; //子目录, 可为空
$upload->autoSub = TRUE; //是否自动生成二级子目录
$upload->subName = array('date','Ymd'); //子目录规则
$info = $upload->upload(); //文件上传
if(!$info) {
$this->error($upload->getError()); //获取错误信息
}else{
// 上传成功后获取上传文件信息,进行后续处理
//mode操作
//$this->ajaxReturn() 可以进行文件的ajax上传(需要客户端js脚本配合)
}
}
}
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools