...
|
...
|
@@ -16,9 +16,9 @@ use app\common\library\Upload; |
|
|
use fast\Tree;
|
|
|
use think\Config;
|
|
|
use think\Db;
|
|
|
use addons\qiniu\library\Qiniu\Auth as QAuth;
|
|
|
use think\Request;
|
|
|
use Qiniu\Auth as QAuth;
|
|
|
use Qiniu\Storage\UploadManager;
|
|
|
use addons\qiniu\library\Qiniu\Storage\UploadManager;
|
|
|
|
|
|
/**
|
|
|
*
|
...
|
...
|
@@ -50,22 +50,20 @@ class Task extends Api |
|
|
* 文件上传
|
|
|
*
|
|
|
*/
|
|
|
public function fileUpload()
|
|
|
public static function fileUpload($file)
|
|
|
{
|
|
|
// file_put_contents("test_upload.log","00:".date("Ymd H:i:s").PHP_EOL,FILE_APPEND);
|
|
|
|
|
|
if ($this->request->isPost()) {
|
|
|
$file = request()->file('file');
|
|
|
$data['oldname'] = request()->post('fileName');
|
|
|
//$data['oldname'] = request()->post('fileName');
|
|
|
// file_put_contents("test_upload.log","一:".date("Ymd H:i:s").json_encode($file).PHP_EOL,FILE_APPEND);
|
|
|
// file_put_contents("test_upload.log","二:".date("Ymd H:i:s").json_encode($data).PHP_EOL,FILE_APPEND);
|
|
|
|
|
|
if (empty($file)) {
|
|
|
$this->error('请选择上传文件');
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
//移动到框架应用根目录/public/uploads/目录下
|
|
|
$info = $file->validate(['ext' => 'jpeg,jpg,png,bmp,doc,docx,pdf,ppt,pptx,xls,xlsx,zip,rar,7z,mp3,mp4,mov'])->move(ROOT_PATH . 'public' . DS . 'uploads');
|
|
|
//$info = $file->validate(['ext' => 'jpeg,jpg,png,bmp,doc,docx,pdf,ppt,pptx,xls,xlsx,zip,rar,7z,mp3,mp4,mov'])->move(ROOT_PATH . 'public' . DS . 'uploads');
|
|
|
// file_put_contents("test_upload.log","三:".date("Ymd H:i:s").json_encode($data).PHP_EOL,FILE_APPEND);
|
|
|
|
|
|
|
...
|
...
|
@@ -77,23 +75,21 @@ class Task extends Api |
|
|
|
|
|
// 构建 UploadManager 对象
|
|
|
$uploadMgr = new UploadManager();
|
|
|
|
|
|
if ($info) {
|
|
|
$filepath = ROOT_PATH . 'public/uploads/' . date('Ymd', time()) . '/' . $info->getFilename();
|
|
|
$fname = 'uploads/' . date('Ymd', time()) . '/' . $info->getFilename();
|
|
|
if ($file) {
|
|
|
$filepath = ROOT_PATH . 'public/uploads/' . $file;
|
|
|
$fname = 'uploads/' . date('Ymd', time()) . '/' . $file;
|
|
|
list($ret, $err) = $uploadMgr->putFile($token, $fname, $filepath);
|
|
|
$data['filepath'] = $domain . $ret['key'];
|
|
|
$data['fileurl'] = '/' . $ret['key'];
|
|
|
$data['fileurl'] = $ret['key'];
|
|
|
$path = '../public' . $data['fileurl'];
|
|
|
is_file($path) && unlink($path);//删除服务器上文件
|
|
|
|
|
|
$this->success('文件上传成功', $data);
|
|
|
return $data;
|
|
|
} else {
|
|
|
//上传失败获取错误信息
|
|
|
// file_put_contents("test_upload.log","四:".$file->getError().PHP_EOL,FILE_APPEND);
|
|
|
|
|
|
$this->error($file->getError());
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
/**
|
...
|
...
|
|