155 lines
4.5 KiB
PHP
155 lines
4.5 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\controller;
|
|
|
|
use think\facade\Session;
|
|
use think\facade\Filesystem;
|
|
use think\facade\Db;
|
|
|
|
class Upload extends Base {
|
|
|
|
// 使用内置PHP模板引擎渲染模板输出
|
|
protected $tpl_config = [
|
|
'view_dir_name' => 'view',
|
|
'tpl_replace_string' => [
|
|
'__static__' => '/static',
|
|
'__img__' => '/static/admin/images',
|
|
'__css__' => '/static/admin/css',
|
|
'__js__' => '/static/admin/js',
|
|
'__plugins__' => '/static/plugins',
|
|
'__public__' => '/static/admin',
|
|
],
|
|
];
|
|
|
|
public $data = ['data' => [], 'code' => 0, 'msg' => ''];
|
|
|
|
protected function initialize() {
|
|
}
|
|
|
|
public function index(){
|
|
$param = $this->request->get();
|
|
|
|
if (!isset($param['name'])) {
|
|
return $this->error('非法操作');
|
|
}
|
|
$this->data = [
|
|
'from' => $this->request->param('from'),
|
|
'param' => $param,
|
|
'require' => [
|
|
'jsname' => 'upload',
|
|
'actionname' => 'index'
|
|
]
|
|
];
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function server(){
|
|
$param = $this->request->get();
|
|
if (!isset($param['name'])) {
|
|
return $this->error('非法操作');
|
|
}
|
|
$pageConfig = [
|
|
'list_rows' => $this->request->param('list_rows', 20),
|
|
'page' => $this->request->param('page', 1),
|
|
'query' => $this->request->param()
|
|
];
|
|
if($param['type'] == 'file'){
|
|
$list = Db::name('File')->paginate($pageConfig);
|
|
}else{
|
|
$list = Db::name('Picture')->paginate($pageConfig);
|
|
}
|
|
|
|
$this->data = [
|
|
'from' => $this->request->param('from'),
|
|
'param' => $param,
|
|
'list' => $list,
|
|
'page' => $list->render(),
|
|
'require' => [
|
|
'jsname' => 'upload',
|
|
'actionname' => 'server'
|
|
]
|
|
];
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function upload(){
|
|
$upload_type = $this->request->get('filename', 'image', 'trim');
|
|
$config = $this->$upload_type();
|
|
// 获取表单上传文件 例如上传了001.jpg
|
|
$file = request()->file('file');
|
|
try {
|
|
validate(['file'=>'filesize:10240|fileExt:jpg|image:200,200,jpg'])
|
|
->check([$file]);
|
|
$data['code'] = 1;
|
|
$data['info'] = $this->save($file, $upload_type);
|
|
} catch (think\exception\ValidateException $e) {
|
|
$data['code'] = 0;
|
|
$data['info'] = $e->getMessage();
|
|
}
|
|
return json($data);
|
|
}
|
|
|
|
protected function image(){
|
|
return [];
|
|
}
|
|
|
|
public function editor(){
|
|
$fileType = $this->request->get('fileType', 'image', 'trim');
|
|
$file = request()->file('imgFile');
|
|
$data['data']['url'] = '/uploads/' . Filesystem::disk('public')->putFile($fileType, $file, 'md5');
|
|
$data['code'] = "000";
|
|
return json($data);
|
|
}
|
|
|
|
public function filemanage(){
|
|
return [];
|
|
}
|
|
|
|
public function ueditor(){
|
|
$data = new \com\Ueditor(Session::get('userInfo.uid'));
|
|
echo $data->output();
|
|
}
|
|
|
|
public function delete(){
|
|
$id = $this->request->param('id', 0);
|
|
if(!$id){
|
|
$data = [
|
|
'status' => false
|
|
];
|
|
}else{
|
|
$data = [
|
|
'status' => true
|
|
];
|
|
}
|
|
return json($data);
|
|
}
|
|
|
|
protected function save($file, $upload_type){
|
|
$data = [];
|
|
$savename = Filesystem::disk('public')->putFile($upload_type, $file, 'md5');
|
|
|
|
$data['create_time'] = $file->getATime(); //最后访问时间
|
|
$data['savename'] = $file->getBasename(); //获取无路径的basename
|
|
$data['c_time'] = $file->getCTime(); //获取inode修改时间
|
|
$data['ext'] = $file->getExtension(); //文件扩展名
|
|
$data['name'] = $file->getFilename(); //获取文件名
|
|
$data['m_time'] = $file->getMTime(); //获取最后修改时间
|
|
$data['owner'] = $file->getOwner(); //文件拥有者
|
|
$data['savepath'] = $file->getPath(); //不带文件名的文件路径
|
|
$data['url'] = $data['path'] = '/uploads/' . $savename; //全路径
|
|
$data['size'] = $file->getSize(); //文件大小,单位字节
|
|
$data['is_file'] = $file->isFile(); //是否是文件
|
|
$data['is_execut'] = $file->isExecutable(); //是否可执行
|
|
$data['is_readable'] = $file->isReadable(); //是否可读
|
|
$data['is_writable'] = $file->isWritable(); //是否可写
|
|
$data['md5'] = md5_file($file->getPathname());
|
|
$data['sha1'] = sha1_file($file->getPathname());
|
|
return $data;
|
|
}
|
|
} |