12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\worker\controller;
- use think\facade\Session;
- use think\facade\Request;
- use think\facade\Filesystem;
- use app\common\model\Attachment as AttachmentModel;
- class Attachment
- {
-
-
- // 文件上传
- public function tplFieldFile()
- {
- $file = request()->file("file");
- $savename = \think\facade\Filesystem::disk('public')->putFile('files',$file);
- if($file){
- $filename = str_replace(strrchr($_FILES['file']['name'], "."),"",$_FILES['file']['name']);
- $attachment = AttachmentModel::create([
- 'filename' => $filename,
- 'atype' => 4,
- 'attachment' => request()->domain() ."/attachment/". str_replace("\\","/",$savename),
- 'createtime' => time()
- ]);
- exit(json_encode(array(
- 'code' => 0,
- 'msg' => "",
- 'data' => array(
- 'src' => request()->domain() ."/attachment/". str_replace("\\","/",$savename),
- 'path' => "./attachment/". str_replace("\\","/",$savename),
- 'title' => $filename
- )
- )));
- }else{
- exit(json_encode(array(
- 'code' => 1,
- 'msg' => "上传失败,请稍后重试"
- )));
- }
- }
-
- // 图片上传
- public function tplFieldImage()
- {
- $file = request()->file("file");
- $savename = \think\facade\Filesystem::disk('public')->putFile('images',$file);
- if($file){
- $filename = str_replace(strrchr($_FILES['file']['name'], "."),"",$_FILES['file']['name']);
- $attachment = AttachmentModel::create([
- 'filename' => $filename,
- 'atype' => 1,
- 'attachment' => request()->domain() ."/attachment/". str_replace("\\","/",$savename),
- 'createtime' => time()
- ]);
- exit(json_encode(array(
- 'code' => 0,
- 'msg' => "",
- 'data' => array(
- 'src' => request()->domain() ."/attachment/". str_replace("\\","/",$savename),
- 'title' => $filename
- )
- )));
- }else{
- exit(json_encode(array(
- 'code' => 1,
- 'msg' => "上传失败,请稍后重试"
- )));
- }
- }
-
-
-
- }
|