Home > Article > Backend Development > PHP drag and drop to upload images to Qiniu Cloud
OSS object storage is a safe, low-cost, and highly reliable cloud storage service. This article uses image uploading combined with Qiniu Cloud Storage as an example to implement the OSS storage function.
php Qiniu Cloud Installation
Use composer to install
#安装 Composer curl -sS https://getcomposer.org/installer | php #使用 Composer 获取最新版本的 Qiniu SDK php composer.phar require qiniu/php-sdk #代码中 require Composer生成的 autoloaderphpUse Qiniu sdk
uploadToken($bucket); // 初始化 UploadManager 对象并进行文件的上传 $uploadMgr = new UploadManager(); if($_FILES){ $key = $_FILES["file"]["name"]; // 调用 UploadManager 的 putFile 方法进行文件的上传 list($ret, $err) = $uploadMgr->putFile($token, $key, $_FILES["file"]["tmp_name"]); if ($err !== null) { var_dump($err); } else { $data['code'] = 1; $data['message'] = 'success'; $data['img_url'] = 'http://7xplx9.com1.z0.glb.clouddn.com/'.$ret['key']; $data['markdown_img'] = '[站外图片上传中……(2)]'; //markdown的图片加载格式 exit( json_encode($data)); } }
html upload Page, use
Use dropzone drag and drop upload plug-in
图片上传 图片上传
Main Content Section
The above is the detailed content of PHP drag and drop to upload images to Qiniu Cloud. For more information, please follow other related articles on the PHP Chinese website!