|
...
|
...
|
@@ -25,7 +25,7 @@ class FileController |
|
|
|
|
|
|
|
public $config = '';
|
|
|
|
|
|
|
|
public $thr_path = '';
|
|
|
|
public $uploads = '';
|
|
|
|
|
|
|
|
public $request = '';
|
|
|
|
|
|
...
|
...
|
@@ -33,7 +33,8 @@ class FileController |
|
|
|
{
|
|
|
|
$this->request = request();
|
|
|
|
$this->config = config('filesystems.disks.upload');
|
|
|
|
$this->path = $this->config['root'].'/file/';
|
|
|
|
$this->uploads = config('uploads.default_file');
|
|
|
|
$this->path = $this->config['root'].$this->uploads['path'].'/';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -43,7 +44,7 @@ class FileController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/5/9 9:15
|
|
|
|
*/
|
|
|
|
public function index($hash = ''){
|
|
|
|
public function index($hash = '',$type = 1){
|
|
|
|
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
|
|
|
header("HTTP/1.1 304 Not Modified");
|
|
|
|
exit;
|
|
...
|
...
|
@@ -59,6 +60,7 @@ class FileController |
|
|
|
}
|
|
|
|
$content = file_get_contents($path);
|
|
|
|
$header['Content-Length'] = $info['size'];
|
|
|
|
$header['Content-Type'] = 'video/'.$info['type'];
|
|
|
|
return response($content, 200, $header);
|
|
|
|
}
|
|
|
|
/**
|
|
...
|
...
|
@@ -66,9 +68,9 @@ class FileController |
|
|
|
*/
|
|
|
|
public function upload() {
|
|
|
|
$this->request->validate([
|
|
|
|
'image'=>['required'],
|
|
|
|
'file'=>['required'],
|
|
|
|
],[
|
|
|
|
'image.required'=>'图片必须填写',
|
|
|
|
'file.required'=>'必须填写',
|
|
|
|
]);
|
|
|
|
$files = $this->request->file('file');
|
|
|
|
if (empty($files)) {
|
|
...
|
...
|
@@ -112,7 +114,7 @@ class FileController |
|
|
|
if ($rs === false) {
|
|
|
|
return $this->response('添加失败', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
return $hash;
|
|
|
|
return $this->response('资源',Code::SUCCESS,['file'=>$hash]);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 多文件上传
|
|
...
|
...
|
@@ -149,7 +151,7 @@ class FileController |
|
|
|
$data[] = $hash;
|
|
|
|
}
|
|
|
|
$fileModel->insert($save_data);
|
|
|
|
return $data;
|
|
|
|
return $this->response('资源',Code::SUCCESS,['files'=>$data]);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @name 统一返回参数
|
|
...
|
...
|
@@ -163,10 +165,46 @@ class FileController |
|
|
|
$result = [
|
|
|
|
'msg' => $msg == ' ' ? $code->description : $msg,
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $data,
|
|
|
|
'data' => $this->_extents($data),
|
|
|
|
];
|
|
|
|
$this->header['Content-Type'] = $type;
|
|
|
|
$response = response($result,$result_code,$this->header);
|
|
|
|
throw new HttpResponseException($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
* @name :返回参数处理
|
|
|
|
* @return array|string
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
protected function _extents($data) {
|
|
|
|
|
|
|
|
if (empty($data) || !is_array($data)) {
|
|
|
|
return empty($data) ? is_array($data) ? [] : '' : $data;
|
|
|
|
}
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if (is_array($v)) {
|
|
|
|
$data[$k] = $this->_extents($v);
|
|
|
|
} else {
|
|
|
|
if (is_null($v)) {
|
|
|
|
$data[$k] = '';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch ((string) $k) {
|
|
|
|
case 'file':
|
|
|
|
$data['file_link'] = url('/b/file_hash/' . $v .'/'.rand(100,999));
|
|
|
|
break;
|
|
|
|
case 'files':
|
|
|
|
$v = explode(',',$v);
|
|
|
|
foreach ($v as $k1=>$v1){
|
|
|
|
$data['files_link'][$k1] = url('/b/file_hash/' . $v1 . '/'.rand(100,999));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|