4 changed files with 147 additions and 69 deletions
			
			
		- 
					75app/Admin/Common/CustomFileController.php
 - 
					44app/Admin/Controllers/v3/CustomFileController.php
 - 
					48app/Admin/Forms/v3/GoodsActivityCopyForm.php
 - 
					49app/Admin/Forms/v3/GoodsCopyForm.php
 
@ -0,0 +1,75 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Common; | 
				
			|||
 | 
				
			|||
use Dcat\Admin\Traits\HasUploadedFile; | 
				
			|||
 | 
				
			|||
class CustomFileController | 
				
			|||
{ | 
				
			|||
    /** | 
				
			|||
     * 自定义上传 | 
				
			|||
     */ | 
				
			|||
    use HasUploadedFile; | 
				
			|||
 | 
				
			|||
    public function handle() | 
				
			|||
    { | 
				
			|||
        $disk = $this->disk('oss'); | 
				
			|||
 | 
				
			|||
        // 判断是否是删除文件请求
 | 
				
			|||
        if ($this->isDeleteRequest()) { | 
				
			|||
            // 删除文件并响应
 | 
				
			|||
            return $this->deleteFileAndResponse($disk); | 
				
			|||
        } | 
				
			|||
 | 
				
			|||
        // 获取上传的文件
 | 
				
			|||
        $file = $this->file(); | 
				
			|||
 | 
				
			|||
        // 获取上传的字段名称
 | 
				
			|||
        // $column = $this->uploader()->upload_column;
 | 
				
			|||
 | 
				
			|||
        // 图片拓展名
 | 
				
			|||
        // $fileOriginalExtension = '.png';
 | 
				
			|||
 | 
				
			|||
        $fileName = md5(time().rand(0000,9999)); | 
				
			|||
 | 
				
			|||
        $dir = 'mp_images'; | 
				
			|||
        $newName = date('Y-m-d-').$fileName.'.'.$file->getClientOriginalExtension(); | 
				
			|||
 | 
				
			|||
        $result = $disk->putFileAs($dir, $file, $newName); | 
				
			|||
 | 
				
			|||
        $path = "{$dir}/$newName"; | 
				
			|||
 | 
				
			|||
        return $result | 
				
			|||
            ? $this->responseUploaded($path, $disk->url($path)) | 
				
			|||
            : $this->responseErrorMessage('文件上传失败'); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 复制文件 | 
				
			|||
     * @param $imageDir 存储文件夹 | 
				
			|||
     * @param $filePath 文件相对路径 | 
				
			|||
     */ | 
				
			|||
    public function autoCopyFile($imageDir, $file) | 
				
			|||
    { | 
				
			|||
        $disk = $this->disk('oss'); | 
				
			|||
 | 
				
			|||
        $result = false; | 
				
			|||
        if($disk->exists($file)){ | 
				
			|||
 | 
				
			|||
            // 图片拓展名
 | 
				
			|||
            $fileOriginalExtension = pathinfo($file)['extension']; | 
				
			|||
 | 
				
			|||
            $fileName = md5(time().rand(0000,9999)); | 
				
			|||
 | 
				
			|||
            $dir = $imageDir; | 
				
			|||
            $newName = 'copy_'.$fileName.'.'.$fileOriginalExtension; | 
				
			|||
            $path = "{$dir}/$newName"; | 
				
			|||
             | 
				
			|||
            $result = $disk->copy($file, $path); | 
				
			|||
        }; | 
				
			|||
         | 
				
			|||
        return $result | 
				
			|||
            ? ['status' => true , 'msg' => '文件复制成功', 'path' => $path, 'url' => $disk->url($path)] | 
				
			|||
            : ['status' => false , 'msg' => '文件复制失败']; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -1,44 +0,0 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Controllers\v3; | 
				
			|||
 | 
				
			|||
use Dcat\Admin\Traits\HasUploadedFile; | 
				
			|||
 | 
				
			|||
class CustomFileController | 
				
			|||
{ | 
				
			|||
    /** | 
				
			|||
     * 自定义上传 | 
				
			|||
     */ | 
				
			|||
    use HasUploadedFile; | 
				
			|||
 | 
				
			|||
    public function handle() | 
				
			|||
    { | 
				
			|||
        $disk = $this->disk('oss'); | 
				
			|||
 | 
				
			|||
        // 判断是否是删除文件请求
 | 
				
			|||
        if ($this->isDeleteRequest()) { | 
				
			|||
            // 删除文件并响应
 | 
				
			|||
            return $this->deleteFileAndResponse($disk); | 
				
			|||
        } | 
				
			|||
 | 
				
			|||
        // 获取上传的文件
 | 
				
			|||
        $file = $this->file(); | 
				
			|||
        var_dump($file); | 
				
			|||
dd($file); | 
				
			|||
        // 获取上传的字段名称
 | 
				
			|||
        $column = $this->uploader()->upload_column; | 
				
			|||
 | 
				
			|||
        $fileName = md5(time()); | 
				
			|||
 | 
				
			|||
        $dir = 'mp_images'; | 
				
			|||
        $newName = date('Y-m-d').$fileName.'.'.$file->getClientOriginalExtension(); | 
				
			|||
 | 
				
			|||
        $result = $disk->putFileAs($dir, $file, $newName); | 
				
			|||
 | 
				
			|||
        $path = "{$dir}/$newName"; | 
				
			|||
 | 
				
			|||
        return $result | 
				
			|||
            ? $this->responseUploaded($path, $disk->url($path)) | 
				
			|||
            : $this->responseErrorMessage('文件上传失败'); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue