public function upload(FileRequest $request)
 {
     $response = array();
     $files = array('files' => $request->file('files'));
     $validator = \Validator::make($files, $request->rules());
     if ($validator->fails()) {
         $response = $validator->errors();
     } else {
         //$file=$request->file('files');
         if ($request->hasFile('files') && $request->has('id')) {
             $file = $request->file('files');
             $product = Product::find($request->get('id'));
             if ($this->process($file, $product)) {
                 $response = ['files' => ['file' => ['path' => '/uploads/' . $product->model . '/' . $this->photo, 'name' => $this->photo]]];
             } else {
                 $response = ['error' => 'Ошибка загрузки изображения!'];
             }
         }
     }
     return response()->json($response);
 }
 public function file(FileRequest $request)
 {
     $file = $request->file('upload');
     $data['name'] = $file->getClientOriginalName();
     $data['path'] = base_path() . '/public';
     $data['slug'] = Str::slug($file->getClientOriginalName(), '_');
     //$data['type'] = "upload";
     //Upload::create($data);
     $file->move($data['path'], $data['name']);
     //
     return back()->with('message', 'file saved!');
 }
 public function reporter(Requests\FileRequest $request)
 {
     $request->file('filename')->move(storage_path(), 'report.txt');
     return redirect(route('reportResult'));
 }
Beispiel #4
0
 /**
  * Function Store
  * to Save/Update Brand From Brand Form
  * @Request @Name,@Code etc
  *
  * @return json
  */
 public function onStore(\App\Http\Requests\FileRequest $request)
 {
     $filename = "";
     if ($request->file('image') != null) {
         $file = $request->file('image');
         $filename = $file->getClientOriginalName();
         $upload = $file->move(base_path() . '/public/uploads/', $filename);
     }
     $files = new \App\Models\File();
     if ($request->has('id')) {
         $files = $files->where('id', $request->get('id'))->first();
         //delete file exists
         \App\Models\FileUser::where('file_id', $request->get('id'))->delete();
         $files->updated_at = date('Y-m-d H:i:s');
         $files->updated_by = Auth::user()->id;
     } else {
         $files->created_at = date('Y-m-d H:i:s');
         $files->created_by = Auth::user()->id;
     }
     if ($filename != "") {
         $files->name = $filename;
         $files->mime = $file->getClientMimeType();
     }
     $files->user_access = "";
     $files->description = $request->get('description');
     $files->company_id = $request->get('company_id');
     $files->date = preg_replace('!(\\d+)/(\\d+)/(\\d+)!', '\\3-\\2-\\1', $request->get('date'));
     $files->active = $request->get('active') ? $request->get('active') : 0;
     $files->save();
     //User Files
     $user = $request->get('users');
     $user_selected = count($user);
     if ($user_selected > 0) {
         $user_access = "";
         for ($i = 0; $i < $user_selected; $i++) {
             if (isset($user[$i])) {
                 $file_users = new \App\Models\FileUser();
                 $file_users->user_id = $user[$i];
                 $file_users->file_id = $files->id;
                 $file_users->save();
                 //Search User
                 $User = \App\Models\User::where('id', $user[$i])->first();
                 if ($i > 0) {
                     $user_access .= ',';
                 }
                 if ($User) {
                     $user_access .= $User->first_name;
                 }
             }
         }
         $ufile = \App\Models\File::where('id', $files->id)->first();
         $ufile->user_access = $user_access;
         $ufile->save();
     }
     if ($files) {
         $param['message'] = Lang::get('info.inserted');
         $param['error'] = false;
     } else {
         $param['message'] = Lang::get('message.file error');
         $param['error'] = true;
     }
     return json_encode($param);
 }