Example #1
0
 public function uploadThumbAndMainImage(Request $request)
 {
     // get basic info
     $s3 = Storage::disk('s3');
     $file = $request->file('file');
     $extension = $request->file('file')->guessExtension();
     $filename = uniqid() . '.' . $extension;
     $mimeType = $request->file('file')->getClientMimeType();
     $fileSize = $request->file('file')->getClientSize();
     $image = Image::make($file);
     $galleryId = $request->input('galleryId');
     // generate the thumb and medium image
     $imageThumb = Image::make($file)->fit(320)->crop(320, 240, 0, 0);
     $imageThumb->encode($extension);
     $imageMedium = Image::make($file)->resize(800, null, function ($constraint) {
         $constraint->aspectRatio();
     });
     $imageMedium->encode($extension);
     $image->encode($extension);
     // upload image to S3
     $s3->put("gallery_{$galleryId}/main/" . $filename, (string) $image, 'public');
     $s3->put("gallery_{$galleryId}/medium/" . $filename, (string) $imageMedium, 'public');
     $s3->put("gallery_{$galleryId}/thumb/" . $filename, (string) $imageThumb, 'public');
     // make image entry to DB
     $file = File::create(['file_name' => $filename, 'mime_type' => $mimeType, 'file_size' => $fileSize, 'file_path' => env('S3_URL') . "gallery_{$galleryId}/main/" . $filename, 'type' => 's3']);
     DB::table('gallery_images')->insert(['gallery_id' => $galleryId, 'file_id' => $file->id]);
     $fileImg = File::find($file->id);
     $fileImg->status = 1;
     $fileImg->save();
     return ['file' => $fileImg, 'file_id' => $file->id, 'thumbUrl' => env('S3_URL') . "gallery_{$galleryId}/thumb/" . $filename, 'url' => env('S3_URL') . "gallery_{$galleryId}/medium/" . $filename, 'main' => env('S3_URL') . "gallery_{$galleryId}/main/" . $filename];
 }
 public function destroy($userId, $fileId)
 {
     $file = \App\File::find($fileId);
     $storagePath = storage_path() . '/documentos/' . $userId;
     $file->delete();
     unlink($storagePath . '/' . $file->name);
     return redirect()->back()->with('success', 'Arquivo removido com sucesso!');
 }
Example #3
0
 public function deleteArticleAttachment(Request $request)
 {
     $user = Auth::user();
     $file = File::find($request->input('attachment'));
     if ($user->id == $file->user_id) {
         $file->delete();
     }
 }
Example #4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $file = File::find($id);
     $file->version_id = $request->input('version_id');
     $file->source = $request->input('source');
     $file->name = $request->input('name');
     $file->save();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $file = File::find($id);
     if (is_null($file)) {
         return response()->json(['error' => 'No file found with ID ' . $id], 404);
     }
     $file->delete();
     unlink(public_path('assets/files/' . $file->contact->name . '/' . $file->name));
     return $file;
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function assignFile(Request $request)
 {
     $file = File::find($request->input('fileId'));
     if ($file != NULL && $request->has($file->version_id)) {
         $file->version_id = $request->input('versionId');
         $file->save();
     } else {
         abort(500, $file . 'This file already assigned with a version!');
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $file = File::find($id);
     if ($file) {
         FileManager::delete(public_path() . $file->path);
         $file->delete();
         return response()->json(['data' => "The file with id {$file->id} was removed"], 200);
     }
     return response()->json(['message' => 'Does not exist a file with that id'], 404);
 }
 public function getDownload($id)
 {
     $file = File::find($id);
     $s3 = Storage::disk('s3');
     if ('s3' == $file->type) {
         $fileUrl = env('S3_URL') . $file->file_path;
         return $fileUrl;
     }
     // $downloadUrl = $s3->getObjectUrl(env('S3_BUCKET'), 'data.txt', '+5 minutes', array(
     //     'ResponseContentDisposition' => 'attachment; filename="' . $file->fileName . '"',
     // ));
     // $filePath = $this->filePath . $file->file_name;
     // return response()->download($filePath);
 }
 /**
  * Create photos matching given share id download response.
  *
  * @param  int|string $id
  * @return string
  */
 public function createDownload()
 {
     $items = $this->splitFilesAndFolders();
     $downloads = [];
     foreach ($items['folders'] as $id) {
         $downloads = $this->addFolder($id, $downloads);
     }
     foreach ($items['files'] as $id) {
         $file = File::find($id);
         $downloads[$this->getName($file)] = $file->getAbsolutePath();
     }
     $fileName = $this->createZip(base_path('storage/zips'), $downloads);
     return $fileName;
 }
Example #10
0
 public function delete(Request $request)
 {
     if (isset($request->id)) {
         $upload = File::find($request->id);
         $upload->delete();
         unlink(public_path('uploads/files/' . $upload->filename));
         unlink(public_path('uploads/files/thumb_' . $upload->filename));
         if (!isset(File::find($request->id)->filename)) {
             $success = new stdClass();
             $success->{$upload->filename} = true;
             return Response::json(array('files' => array($success)), 200);
         }
     }
 }
Example #11
0
 public static function LogBrowse($file_id)
 {
     $fileInfo = File::find(intval($file_id));
     if ($fileInfo == null) {
         return false;
     }
     $fileInfo->view_times += 1;
     $fileInfo->save();
     $log = new BrowseLog();
     $log->page = $file_id;
     $log->ip = LogController::getIP();
     $log->user_agent = LogController::getUA();
     $log->save();
     return true;
 }
Example #12
0
 public function get($id)
 {
     // $entry = File::where('filename', '=', $filename)->firstOrFail();
     // $file = \Storage::disk('local')->get($entry->filename);
     // // return (new \Response($file, 200))
     //             // ->header('Content-Type', $entry->mime);
     // return response($file,200)
     //           ->header('Content-Type', $entry->mime);
     // ===============================================================================================
     // $entry = File::where('filename', '=', $filename)->firstOrFail();
     // 	if (\Storage::exists($entry->filename)) {
     // 	$file = \Storage::disk('local')->get($entry->filename);
     // 	// return (new \Response($file, 200))
     //              // ->header('Content-Type', $entry->mime);
     // 	return response($file,200)
     //            ->header('Content-Type', $entry->mime);
     // 	}
     // 	else{
     // 		return 'File Rusak atau tidak ditemukan, Silahkan Update Ulang ';
     // 	}
     $entry = File::find(base64_decode($id));
     // dd($entry);
     if ($entry) {
         $dirfile = empty($entry->nama_baru) ? $entry->filename : $entry->dir . '/' . $entry->nama_baru;
         // echo $dirfile;
         // ARSIPPROSESSP2D-UYUYphpFDCC.tmp.pdf
         // dinas-p/ARSIPPROSESSP2D-UYUYphpF441.tmp.pdf
         // dd($dirfile);
         // dd($dirfile);
         // "SEKWAN-II/164-sp2d-nhl-setwn-09-arsipprosessp2d-164-sp2d-nhl-setwn-09-phpCAC5.tmp.pdf";
         // "164-sp2d-nhl-setwn-09-arsipprosessp2d-164-sp2d-nhl-setwn-09-1-php757E.tmp"
         if (\Storage::exists($dirfile)) {
             $file = \Storage::get($dirfile);
             // return (new \Response($file, 200))
             // ->header('Content-Type', $entry->mime);
             return response($file, 200)->header('Content-Type', $entry->mime);
         } elseif (!empty($entry->filename) && \Storage::exists($entry->filename)) {
             $file = \Storage::get($entry->filename);
             // return (new \Response($file, 200))
             // ->header('Content-Type', $entry->mime);
             return response($file, 200)->header('Content-Type', $entry->mime);
         } else {
             return 'File tidak ditemukan, Silahkan Update Ulang ';
         }
     } else {
         return 'Data File Rusak atau tidak ditemukan, Silahkan Update Ulang ';
     }
 }
 /**
  * Handle the event.
  *
  * @param  UserUpdated  $event
  * @return void
  */
 public function handle(UserUpdated $event)
 {
     $user = $event->user;
     $dirty = $user->getDirty();
     $original = $user->getOriginal();
     if (array_key_exists('government_identification_id', $dirty)) {
         $file = File::find($original['government_identification_id']);
         if ($file) {
             $file->delete();
         }
     }
     if (array_key_exists('avatar_id', $dirty)) {
         $file = File::find($original['avatar_id']);
         if ($file) {
             $file->delete();
         }
     }
 }
 public function postImageDelete(Request $request)
 {
     $file = File::find($request->get('id'))->delete();
     return response()->json(['status' => 'success'], 200);
 }
Example #15
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     if (!Auth::user()->can('edit-video')) {
         return view('errors.denied');
     }
     $file = File::find($id);
     return view('video.edit')->with('file', $file);
 }
 public function getDeletebyid(Request $request)
 {
     $this->validate($request, ['id' => 'required'], [], ['id' => '文件ID']);
     if ($request->has('id')) {
         $id = $request->get('id');
         $file = File::find($id);
         if (!$file) {
             return Redirect::back()->withInput()->withErrors(['文件并不存在!']);
         }
         if ($file->upload_id == Auth::user()->id || Auth::user()->role == 'root' || Auth::user()->role == 'admin') {
             Storage::delete($file->path);
             $file->delete();
             $info = array('删除成功!');
             return Redirect::back()->withTips($info);
         } else {
             return Redirect::back()->withInput()->withErrors(['没有权限!']);
         }
     } else {
         return;
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //Finding the file
     $file = File::find($id);
     //Delitting the file
     $file->delete();
     //Sending the user to the index page
     return redirect()->route('file/index');
 }
Example #18
0
 public static function getduongdanfileemail($files)
 {
     $duongdanfiles = array();
     foreach ($files as $file) {
         $duongdanfile = File::find($file);
         $duongdanfiles[] = storage_path() . '/uploads/' . $duongdanfile->name;
     }
     return $duongdanfiles;
 }
 public static function BanFile($id)
 {
     $file = File::find($id);
     if ($file == null) {
         return false;
     }
     $file->banned = true;
     $file->save();
     return true;
 }
Example #20
0
 public function get($id, $name = "")
 {
     $entry = File::find($id);
     $file = Storage::disk('local')->get($entry->saved_name);
     return (new Response($file, 200))->header('Content-Type', $entry->mime);
 }
Example #21
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $file = File::find($id);
     try {
         \File::delete(public_path($file->path));
         $file->delete();
     } catch (\Exception $e) {
         return response()->json(['message' => 'File was not deleted', 'description' => $e->getMessage()], 403);
     }
     return response()->json(['message' => 'File deleted correctly', 'description' => 'File deleted correctly'], 201);
 }
Example #22
0
 public function uploadImage(Request $request)
 {
     $galleryId = $request->input('galleryId');
     // check if the file exist
     if (!$request->hasFile('file')) {
         return response('No file sent.', 400);
     }
     // check if the file is valid file
     if (!$request->file('file')->isValid()) {
         return response('File is not valid.', 400);
     }
     // validation rules
     $validator = Validator::make($request->all(), ['galleryId' => 'required|integer', 'file' => 'required|mimes:jpeg,jpg,png|max:8000']);
     // if validation fails
     if ($validator->fails()) {
         return response('There are errors in the form data', 400);
     }
     // set the file table insert data
     $mimeType = $request->file('file')->getClientMimeType();
     $fileSize = $request->file('file')->getClientSize();
     $fileName = 'gallery_' . $request->input('galleryId') . '_' . uniqid() . '.' . $request->file('file')->guessExtension();
     $s3 = Storage::disk('s3');
     if ($s3->put($fileName, file_get_contents($request->file('file')), 'public')) {
         $file = File::create(['file_name' => $fileName, 'mime_type' => $mimeType, 'file_size' => $fileSize, 'file_path' => env('S3_URL') . $fileName, 'type' => 's3']);
         DB::table('gallery_images')->insert(['gallery_id' => $request->input('galleryId'), 'file_id' => $file->id]);
         $fileImg = File::find($file->id);
         $fileImg->status = 1;
         $fileImg->save();
     }
     return $request->file('files');
 }
Example #23
0
 /**
  * 
  */
 public function postExportToFile(Request $req, $db, $idData)
 {
     // dd($req->all());
     $file = File::find($idData);
     $file_name = $file->filename;
     $keytable = $this->mod($db)->kolom;
     $datapost = $req->all()['data'];
     $readkey = 0;
     // dd($datapost);
     // $ins=\Excel::load($reader="storage\app\/$idData.tmp.xls");
     $ins = \Excel::load($reader = "storage\\app\\/" . $file_name);
     $tmp = $ins->setActiveSheetIndex(0);
     // $tmp=$ins->setActiveSheetIndexByName();
     $template_excel = $tmp->toArray(null, true, true, true);
     // print_r($data);
     $arr = array();
     foreach ($template_excel as $key => $value) {
         $baris = $key;
         if ($key >= 11) {
             foreach ($keytable as $kolom => $header) {
                 // echo $kolom.$baris.' : '.$datapost[$readkey][$header].'--';
                 $tmp->setCellValue($kolom . $baris, $datapost[$readkey][$header]);
                 //ini utnuk update
             }
             // foreach ($value as $key => $value) {
             //     // $row[$model[$key]]=$value;
             // // $bantu=preg_replace("/[^A-Z]/","",$sell);
             // 	// dd($key);
             // 	// dd($keytable[$key]);
             // 	// $data[$readkey][$keytable[]]
             // 	// echo $readkey;
             // 	if (isset($keytable[$key])) {
             //    $tmp->setCellValue($key.$baris,  $datapost[$readkey][$keytable[$key]]) ;//ini utnuk update
             // 	}
             // }
             // $arr[]=(object)$row;
             $readkey++;
         }
     }
     $current_date = date("Y-m-d");
     $nama_file_download = $db . '_' . $current_date . '_' . $idData;
     $ins->setFileName($nama_file_download);
     if ($ins->save('xlsx')) {
         // ca_export=tat ke export table
         $data_export['files_id'] = $file->id;
         $data_export['imports_id'] = $file->import->id;
         $data_export['users_id'] = \Sentry::getUser()->id;
         // $data_export['link_file'] =  route('resultdb.d',['filename'=> $nama_file_download ]) ;
         $data_export['link_file'] = route('resultdb.d', ['tabel' => $db, 'filename' => $nama_file_download]);
         $data_export['status_eksport'] = 'ok ';
         $data_export['nama_file'] = $nama_file_download;
         $data_export['created_at'] = $current_date;
         Eksport::create($data_export);
         $response['msg'] = 'Export Selesaill <br> Silahkan tunggu atau Klik link <a href="' . route('resultdb.d', ['tabel' => $db, 'filename' => $nama_file_download]) . '" >ini</a>';
         $response['download'] = route('resultdb.d', ['tabel' => $db, 'filename' => $nama_file_download]);
         $response['code'] = 200;
         return json_encode($response);
         // ->export('xlsx');
     }
     // $ins=\Excel::load($reader='storage\app\/'.$idData.'.tmp.xlsx');
     // $tmp=$ins->setActiveSheetIndexByName($db);
     // 	$data= $tmp->toArray(null, true,true,true);
     // 	// print_r($data);
     // 	$arr = array();
     // foreach ( $data as $key => $value) {
     // 		$baris=$key;
     // 		if ($key >= 11) {
     // 			foreach ($value as $key => $value) {
     // 					// $row[$model[$key]]=$value;
     // 				$tmp->setCellValue($key.$baris, $value)	;//ini utnuk update
     // 			}
     // 			// $arr[]=(object)$row;
     // 		}
     // }
     // dd($tmp);
     // $tmp->create('Nimit New.xlsx')->store('xlsx');
 }
Example #24
0
 /**
  * 
  */
 public function anyReadExcel($db, $id)
 {
     $file_read_start = 2;
     $file = File::find($id);
     $model = $this->mod($db)->kolom;
     // dd($this->mod($db)->where('files_id',$id)->get()->count());
     if ($this->mod($db)->where('files_id', $id)->get()->count()) {
         $result['total'] = 0;
         $result['rows'] = 0;
         $result['error'] = 'error_step';
         $result['msg'] = 'File Sudah Diimport !!';
         return $result;
     }
     $ModelValidasi = $this->mod($db);
     if ($contents = \Storage::disk('local')->exists($file->filename)) {
         $ext = 'xlsx';
     } elseif ($contents = \Storage::disk('local')->exists($file->filename)) {
         $ext = 'xls';
     }
     $ins = \Excel::load($reader = 'storage\\app\\/' . $file->filename);
     $ins->getSheetByName($db);
     $arr = array();
     if ($ins->getSheetByName($db)) {
         // exit('ada heet');
         $tmp = $ins->setActiveSheetIndexByName($db);
         $data = $tmp->toArray(null, true, true, true);
         // print_r($data);
         // dd($data);
         $arr = array();
         $checkError = '';
         foreach ($data as $key => $dataRow) {
             $baris = $key;
             if ($key >= $file_read_start) {
                 $indexRow = $key;
                 /*validasi data disinii => validasi perbarissss*/
                 // $ModelValidasi=$ModelValidasi;
                 // dd( $mod->validate( $data));
                 // var_dump($dataRow);echo "<br>";
                 $validate = $ModelValidasi->validate($dataRow);
                 $ModelValidasi->validate($dataRow);
                 $messages = $validate->messages();
                 if ($validate->fails()) {
                     //Modifikasi data yang error
                     // var_dump($messages);echo "<br>";
                     foreach ($messages->toArray() as $key => $errorMassage) {
                         $error = '';
                         // dd($errorMassage);
                         foreach ($errorMassage as $value) {
                             $error .= $value;
                         }
                         // $dataRow[$model[$key]]=$dataRow[$key].' Cell : '.$key.$indexRow.'-'.$error;
                         // '<a href="#" title="This is the tooltip message." class="easyui-tooltip">Hover me</a>'
                         // $dataRow[$key]='"'.$dataRow[$key].'" Cell : '.$key.$indexRow.'<a href="#" title="'.$error.'" class="easyui-tooltip">Hover me</a>';
                         if (empty($dataRow[$key])) {
                             $dataRow[$key] = 'kosong';
                         }
                         // $dataRow[$key]='<a href="#" title=" Error : '.$error.', Cell : '.$key.$indexRow.', dengan Nilai :'.$dataRow[$key].' " class="easyui-tooltip" >'.$dataRow[$key].' </a>';
                         $dataRow[$key] = '<a href="#" title=" Error : ' . $error . ', Cell : ' . $key . $indexRow . ', dengan Nilai :' . $dataRow[$key] . ' " class="easyui-tooltip" >' . $dataRow[$key] . ' </a>';
                         $checkError = 'error';
                     }
                     // dd($dataRow);
                 }
                 /*validasi data disinii*/
                 foreach ($dataRow as $key => $value) {
                     $indexCol = $key;
                     // echo $indexCol.$indexRow.'--';
                     //Tulis data ke adalam array
                     if (isset($model[$key])) {
                         $row[$model[$key]] = $value;
                     }
                     // $tmp->setCellValue($key.$baris, $value)	;//ini utnuk update
                 }
                 $arr[] = (object) $row;
             }
         }
         $result['rows'] = $arr;
         $result['error'] = $checkError;
     } else {
         $result['rows'] = $arr;
         $result['error'] = 'file_error';
     }
     // dd($arr);
     // $result['total']=30;
     // $result['rows']=$arr;
     // $result['error']=$checkError;
     return json_encode((object) $result);
 }
Example #25
0
 public function handleAction(Request $request)
 {
     $action = $request->input('_action');
     if ($action == 'addDevice') {
         $this->validate($request, ['serial_number' => 'unique:devices']);
         $date = Device::convertDate($request->input('purchased_at'));
         $id = DB::table('devices')->insertGetId(['serial_number' => $request->input('serial_number'), 'purchased_at' => $date, 'model_id' => $request->input('model_id')]);
         //Device::create( $request->all() );
         return response(['status' => 'success', 'new_added_id' => $id]);
     } else {
         if ($action == 'createRepair') {
             if ($request['device_id'] != '') {
                 $id = File::create($request->all())->id;
                 Repair::create(['file_id' => $id, 'device_id' => $request->input('device_id'), 'accessory' => $request->input('accessory'), 'description' => $request->input('description')]);
                 $leftmenu['files'] = 'active';
                 $param['code_status_id'] = '4';
                 $param['file_id'] = $id;
                 $param['created_at'] = date('d/m/Y, H:i:s');
                 $param['user_id'] = Auth::user()->id;
                 $param['comment'] = '';
                 $response = StatusFile::create($param);
                 File::find($id)->touch();
                 if (isset($request['devis'])) {
                     $param['code_status_id'] = "15";
                     $response = StatusFile::create($param);
                     File::find($id)->touch();
                 }
                 return response(['status' => 'success', 'redirect' => '/file/repair/' . $id]);
             } else {
                 return response(['status' => 'error']);
             }
         } else {
             if ($action == 'createOrder') {
                 $order_details = session()->has('order_details') ? session('order_details') : false;
                 if ($order_details) {
                     $id = File::create($request->all())->id;
                     Order::create(["file_id" => $id, "total_details_amount" => $order_details['total']]);
                     $param['code_status_id'] = '4';
                     $param['file_id'] = $id;
                     $param['created_at'] = date('d/m/Y, H:i:s');
                     $param['user_id'] = Auth::user()->id;
                     $param['comment'] = '';
                     $response = StatusFile::create($param);
                     File::find($id)->touch();
                     foreach ($order_details as $order_item) {
                         if (isset($order_item['price'])) {
                             OrderDetails::create(["file_id" => $id, "article_id" => $order_item['article_id'], "price" => $order_item['price'], "quantity" => $order_item['quantity']]);
                         }
                     }
                     $request->session()->forget('order_details');
                     return response(['status' => 'success', 'redirect' => '/file/order/' . $id]);
                 }
                 return response(['status' => 'error']);
             } else {
                 if ($action == 'calculateOrder') {
                     $list = json_decode($request['_params'], true);
                     $response = Order::calculateTotal($list['orders']);
                     $list['orders']['total'] = $response;
                     $response != 0 ? Session::put('order_details', $list['orders']) : '';
                     $response = $response != 0 ? ['status' => 'success', 'total' => $response] : ['status' => 'error'];
                     return response($response);
                 } else {
                     return response(['status' => 'error']);
                 }
             }
         }
     }
 }
 public function download($userId, $fileId)
 {
     $file = \App\File::find($fileId);
     $storagePath = storage_path() . '/files/' . $userId;
     return \Response::download($storagePath . '/' . $file->name);
 }
 protected function beforeSave(&$Item, $id, &$item, &$request, $func)
 {
     $preserved_data = ['name' => $item->name, 'content' => $item->content];
     parent::beforeSave($Item, $id, $item, $request, $func);
     $preserved = false;
     //check if the uploaded file is valid
     if (!$request->hasFile('content') || !$request->file('content')->isValid()) {
         if (isset($_FILES['content'])) {
             if ($_FILES['content']['error'] >= 1 && $_FILES['content']['error'] <= 4) {
                 if ($func == 'update' && $_FILES['content']['error'] == 4) {
                     $preserved = true;
                 } else {
                     throw new Exception('upload' . $_FILES['content']['error']);
                 }
             } else {
                 $this->exceptionAdd(['upload' => 'Upload file error! [' . $_FILES['content']['error'] . ']']);
                 throw new Exception('upload');
             }
         } else {
             $this->exceptionAdd(['upload' => 'Upload file error! [Unknown]']);
             throw new Exception('upload');
         }
     }
     if ($preserved == true) {
         if (!isset($request['name']) || $request['name'] == '') {
             $item->name = $preserved_data['name'];
         }
         $item->content = $preserved_data['content'];
     } else {
         if ($_FILES['content']['size'] > $this->maxFileSize) {
             throw new Exception('upload2');
         }
         $file = $request->file('content');
         //pre-filesystem
         //generate name automatically
         if (!isset($request['name']) || $request['name'] == '') {
             $item->name = $file->getClientOriginalName();
         }
         //generate path
         $path = date('Y-m-d-H-i-s-') . uniqid();
         $this->encodeFileContent($item, $file->getClientOriginalName(), $path);
         //filesystem
         //delete old file
         if ($func == 'update') {
             $old_item = File::find($id);
             $this->decodeFileContent($old_item);
             $old_path = $old_item->filepath;
             if (file_exists($this->desRoot . $old_path) && !@unlink($this->desRoot . $old_path)) {
                 throw new Exception('delete');
             }
         }
         //move new file
         try {
             $file->move($this->desRoot, $path);
         } catch (Exception $ex) {
             throw new Exception('move');
         }
     }
 }