tp6 文件上傳 驗證是否有文件上傳


$data=Request::post();
            $oldimg=public_path()."storage/".ProductModel::find($data['id'])->img;
            if(file_exists($oldimg)){
                unlink($oldimg);
            }
            try {
                // 獲取表單上傳文件
                $file = Request::file('img');
            } catch (\Exception $e) {
            }
            if(isset($file)){
                // 上傳到本地服務器
                $data['img'] = \think\facade\Filesystem::disk('public')->putFile( '/upload', $file);
            }
            if(ProductModel::update($data)){
                return redirect('index');
            }else{
                return redirect('add');
            }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM