Example #1
0
 /**
  * 收集数据
  */
 public function getData(Request $request, $id = null)
 {
     //判断logo
     $logo = '';
     //给个默认值
     if ($id) {
         $logo = ComMainModel::find($id)->logo;
     }
     //图片上传
     if (!$logo && $request->hasFile('url_ori')) {
         //判断文件存在
         $data['url_ori'] = '';
         //验证图片大小
         foreach ($_FILES as $pic) {
             if ($pic['size'] > $this->uploadSizeLimit) {
                 echo "<script>alert('对不起,你上传的文件大于5M,请重新选择');history.go(-1);</script>";
                 exit;
             }
         }
         $file = $request->file('url_ori');
         //获取文件
         $logo = \App\Tools::upload($file);
     }
     $data = ['title' => $request->title, 'keyword' => $request->keyword, 'description' => $request->description, 'logo' => $logo, 'job' => $request->job, 'job_require' => $request->job_require, 'job_num' => $request->job_num, 'sort' => $request->sort, 'istop' => $request->istop, 'isshow' => $request->isshow];
     return $data;
 }
Example #2
0
 public function update(Request $request, $id)
 {
     //图片上传处理
     if ($request->hasFile('url_ori')) {
         //判断文件存在
         //验证图片大小
         foreach ($_FILES as $pic) {
             if ($pic['size'] > $this->uploadSizeLimit) {
                 echo "<script>alert(\"对不起,你上传的图片过大,请重新选择\");history.go(-1);</script>";
                 exit;
             }
         }
         $file = $request->file('url_ori');
         //获取文件
         $logo = \App\Tools::upload($file);
     }
     $data = ['logo' => isset($logo) ? $logo : '', 'title' => $request->title, 'keyword' => $request->keyword, 'description' => $request->description, 'updated_at' => date('Y-m-d H:i:s', time())];
     //同时删除原有的logo图片
     $mainModel = ComMainModel::find($id);
     if (isset($logo) && $mainModel->logo && $mainModel->logo != $this->sefLogo) {
         unlink(ltrim($mainModel->logo, '/'));
     }
     ComMainModel::where('id', $id)->update($data);
     return redirect('/company/admin/basic');
 }