Example #1
2
 /**
  * 
  */
 public function postUpload(Request $req, $db)
 {
     $response = array();
     $file = $req->file('excelF');
     /*periksa type file excel ======================================================================================*/
     if ($file && ($file->getClientMimeType() == 'application/vnd.ms-excel' or $file->getClientMimeType() == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')) {
         $extension = $file->getClientOriginalExtension();
         $filename = $file->getClientOriginalName();
         if (\Storage::disk('local')->put($file->getFilename() . '.' . $extension, \File::get($file))) {
             // simpan kedadalam table
             $entry = new File();
             $entry->mime = $file->getClientMimeType();
             $entry->original_filename = $file->getClientOriginalName();
             $entry->filename = $file->getFilename() . '.' . $extension;
             $entry->description = $req->get('description', ' Tanpa Deskripsi ! ');
             $entry->db_table = $db;
             $entry->users_id = \Sentry::getUser()->id;
             $entry->save();
             $response['code'] = 200;
             $response['msg'] = "File  {$entry->original_filename} Telah disimpan";
             return $response;
         }
     } elseif ($req->file('excelF')) {
         $extension = $file->getClientOriginalExtension();
         $filename = $file->getClientOriginalName();
         $response['code'] = 404;
         $response['msg'] = "File berextensi {$extension} dengan nama {$filename}, file Seharusnya Berupa Excel";
         // $response['msg']="File Anda   $file->getClientOriginalName(), Pastikan File yang Anda upload sesuai dengan format ";
         return $response;
         // return $response;
     } else {
         $response['code'] = 404;
         $response['msg'] = "Anda belum mimilih format file untuk diupload !!!";
         return json_encode($response);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     $file = new File();
     //$file->size = $request->file('upload')->getSize();
     $file->name = $request->name;
     $file->save();
     $fileName = $file->id . '.' . $request->file('upload')->getClientOriginalExtension();
     $file->size = $request->file('upload')->getSize();
     $request->file('upload')->move(base_path() . '/public/fileuploads/', $fileName);
     $file->url = '/fileuploads/' . $fileName;
     $file->save();
     return redirect('files');
 }
Example #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     // $v = Validator::make($request, [
     //       'type' => 'required',
     //       ]);
     // if ($v->fails())
     // {
     //     return redirect()->back()->withErrors($v->errors())
     //     						 ->withInput();
     // }else{
     //check for uploaded file and store it n public path
     $file = new File();
     $file->name = $request->get('name');
     $file->desc = $request->get('desc');
     $file->type = $request->get('type');
     if ($request->hasFile('file')) {
         $destination = 'files/';
         $filename = str_random(6) . "_" . $request->file('file')->getClientOriginalName();
         $request->file('file')->move($destination, $filename);
         $file->file = $filename;
     } else {
         $file->file = $request->get('file');
     }
     $file->save();
     // }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $file = new File();
     $file->fill($request->all());
     $file->save();
     return $file;
 }
Example #5
0
 public function IdentitasHandle($req, $id)
 {
     // PDF tidak di update / melalui form
     // Gagal mengupload file PDF
     // Sukses Mengupload DOkumen
     $temp_iden_pesan = ['error' => ['user' => 'Peringatan : File PDF tidak di atur dengan benar !', 'sistem' => 'Terjadi kesalahan upload File PDf '], 'succes' => ['store' => 'Sukses mengupload Dokumen PDF ', 'update' => 'Sukses mengupdate Dokumen PDF ']];
     $temp_file_pesan = ['error' => '', 'succes' => ''];
     // dd($req->all());
     $file = $req->file('gambar');
     if ($file and $file->getClientMimeType() == 'application/pdf') {
         // dd($file);
         $extension = $file->getClientOriginalExtension();
         $FileIdentity = File::where('dokumen_id', $id);
         // Update
         if (count($FileIdentity->get()->toArray())) {
             $this->result['identitas']['lama'] = $FileIdentity->get()->toArray();
             //delete file
             $data_for_update = ['mime' => $file->getClientMimeType(), 'original_filename' => $file->getClientOriginalName(), 'filename' => $file->getFilename() . '.' . $extension];
             if ($FileIdentity->update($update)) {
                 $this->result['identitas']['baru'] = $FileIdentity->get()->toArray();
                 $this->{$result}['pesan'] = $temp_iden_pesan['succes']['update'];
                 // proses storage
                 if (\Storage::delete($FileIdentity->get()->toArray()[0]['filename']) && \Storage::disk('local')->put($file->getFilename() . '.' . $extension, \File::get($file))) {
                     $this->file_pesan['succes'] = $temp_file_pesan['succes'];
                     return true;
                 } else {
                     $this->file_pesan['error'] = $temp_file_pesan['error'];
                     return false;
                 }
                 return true;
             } else {
                 return false;
             }
         } else {
             // echo " new file";
             $new_dokument = new File();
             $new_dokument->dokumen_id = $id;
             $new_dokument->mime = $file->getClientMimeType();
             $new_dokument->original_filename = $file->getClientOriginalName();
             $new_dokument->filename = $file->getFilename() . '.' . $extension;
             //new identitas
             if ($new_dokument->save()) {
                 // new pdf
                 if (\Storage::disk('local')->put($file->getFilename() . '.' . $extension, \File::get($file))) {
                     return true;
                 }
                 $this->{$result}['pesan'] = $temp_iden_pesan['succes']['store'];
                 return true;
             } else {
                 $this->{$result}['pesan'] = $temp_iden_pesan['error']['sistem'];
                 return false;
             }
         }
         // }
     } else {
         $this->{$result}['pesan'] = $temp_iden_pesan['error']['user'];
         return false;
     }
 }
Example #6
0
 public static function addNew($name, $file, $description = '', $patient_id = 0)
 {
     $new_file = new File();
     $new_file->name = $name;
     $new_file->description = $description;
     $new_file->patient_id = $patient_id;
     $new_file->save();
     $new_file->assignIcon($file->getClientOriginalExtension());
     $new_file->saveFile($file);
     return $new_file;
 }
 public function store(FileRequest $request)
 {
     if ($this->exist($request->input('num_file'))) {
         return redirect()->to('expedientes/create')->withInput()->withErrors(array('invalid' => 'Ya existe el expediente por favor digite uno distinto'));
     }
     $date = Carbon::now();
     $file = new File($request->all());
     $file->created_at = $date;
     $file->updated_at = $date;
     $file->save();
     return redirect()->route('expedientes.index');
 }
Example #8
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function handleCreate()
 {
     $user_id = Auth::id();
     $user = User::find($user_id);
     $user_name = $user->first_name;
     $date = HelperController::convertCurrentTime();
     $file = Input::file('file');
     $extension = $file->getClientOriginalExtension();
     // getting file extension
     $fileName = $file->getClientOriginalName();
     //$fileName=  HelperController::explodefile($fileName);//explode the file name and file's extension and retrieve only file name
     $path = '/files/' . $user_name . '/' . $date . '/' . $extension;
     $destinationPath = public_path() . $path;
     // upload path
     $upload_success = $file->move($destinationPath, $fileName);
     // uploading file to given path
     if ($upload_success) {
         $file_name_from_db = HelperController::checkFileName($fileName);
         $file_path_from_db = HelperController::checkFilePath($path);
         if ($fileName != $file_name_from_db && $path != $file_path_from_db) {
             /*
              * file data is stored in database
              * 
              */
             $db_file = new File();
             $db_file->file_name = $fileName;
             $db_file->file_path = 'files/' . $user_name . '/' . $date . '/' . $extension;
             $db_file->save();
             $db_file->members()->attach($user_id);
             //check file extension from extension collection
             $ext_from_db = HelperController::checkExtension($extension);
             if ($extension != $ext_from_db) {
                 $db_file_extension = new Extension();
                 $db_file_extension->file_extension = $extension;
                 $db_file_extension->save();
                 $db_file_extension->files()->attach($db_file);
             } elseif ($extension == $ext_from_db) {
                 //$old_extension=  Extension::where('file_extension','=',$extension)->first();
                 //$extension_id=$old_extension->id;
                 $ext_id = HelperController::getExtensionId($extension);
                 $db_file->extensions()->attach($ext_id);
             }
         }
         return Response::json('success', 200);
     } else {
         return Response::json('error', 400);
     }
     //echo $file;
 }
 public static function AddFile($arr)
 {
     if ($arr == null) {
         return false;
     }
     $file = new File();
     $file->filename = $arr['filename'];
     $file->banned = 0;
     $file->size = $arr['size'];
     $file->description = $arr['description'];
     $file->file_path = $arr['filepath'];
     $file->uploader = $arr['uploader'];
     $file->download_times = 0;
     $file->view_times = 0;
     $file->save();
     return $file->id;
 }
Example #10
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $sub = new File();
     $sub->name = "";
     $sub->original_name = "";
     $sub->description = "Poster template";
     $sub->type = "";
     $sub->img_type = "paper";
     $sub->save();
     $sub = new File();
     $sub->name = "";
     $sub->original_name = "";
     $sub->description = "Poster template";
     $sub->type = "";
     $sub->img_type = "poster";
     $sub->save();
 }
Example #11
0
 /**
  * Upload and save file description.
  *
  * @param Symfony\Component\HttpFoundation\File\UploadedFile
  * @return App\File
  */
 public static function upload($uploadedFile)
 {
     if ($uploadedFile != null) {
         $ext = $uploadedFile->getClientOriginalExtension();
         $saved_name = str_random(20) . '.' . $ext;
         $uploadedFile->move(storage_path() . '/upload', $saved_name);
         // we should save this file information in database
         $name = $uploadedFile->getClientOriginalName();
         $ext = $uploadedFile->getClientOriginalExtension();
         $mime = (new MimeTypeGuesser())->guess($ext);
         $size = $uploadedFile->getClientSize();
         $file = compact('saved_name', 'name', 'mime', 'size');
         $file = new File($file);
         $file->save();
         return $file;
     }
     return null;
 }
Example #12
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Motion $motion, Request $request)
 {
     if (!Auth::user()->can('create-motions')) {
         abort(401, 'You do not have permission to create a motion');
     }
     $file = new File();
     $file->uploadFile('motion_files', 'file', $request);
     if (!$file->save()) {
         abort(403, $file->errors);
     }
     $motionFile = new MotionFile();
     $motionFile->motion_id = $motion->id;
     $motionFile->file_id = $file->id;
     if (!$motionFile->save()) {
         abort(403, $motionFile->errors);
     }
     return $motionFile;
 }
Example #13
0
 public function newReview(Request $request)
 {
     $this->validate($request, ['review_name' => 'required|max:255', 'file' => 'required']);
     $id = uniqid();
     $name = $request->input('review_name');
     $file = $request->file('file');
     $review = new Review();
     $review->id = $id;
     $review->name = $name;
     $review->save();
     if ($file->getMimeType() == 'application/zip') {
         $zip = zip_open($request->file('file')->getPathName());
         if (is_resource($zip)) {
             while ($zip_entry = zip_read($zip)) {
                 $name = zip_entry_name($zip_entry);
                 $size = zip_entry_filesize($zip_entry);
                 if (zip_entry_open($zip, $zip_entry, 'r')) {
                     $contents = zip_entry_read($zip_entry, $size);
                     $finfo = new \finfo(FILEINFO_MIME_TYPE);
                     $type = $finfo->buffer($contents);
                     if (in_array($type, File::$AcceptTypes) && File::IsValidNameName($name)) {
                         $dbFile = new File();
                         $dbFile->review_id = $id;
                         $dbFile->contents = $contents;
                         $dbFile->type = $type;
                         $dbFile->name = $name;
                         $dbFile->size = $size;
                         $dbFile->save();
                     }
                 }
                 zip_entry_close($zip_entry);
             }
         }
     } else {
         $dbFile = new File();
         $dbFile->review_id = $id;
         $dbFile->contents = file_get_contents($request->file('file')->getPathname());
         $dbFile->type = $file->getMimeType();
         $dbFile->name = $file->getClientOriginalName();
         $dbFile->size = $file->getClientSize();
         $dbFile->save();
     }
     return redirect('reviews/' . $id);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make(array('image' => Input::file('image')), array('image' => 'image'));
     if ($validator->fails()) {
         abort(403, 'file is not an image');
     }
     $file = new File();
     $file->uploadFile('background_images', 'background_images', $request);
     if (!$file->save()) {
         abort(403, $file->errors);
     }
     $backgroundImage = (new BackgroundImage())->secureFill($request->all());
     $backgroundImage->user_id = Auth::user()->id;
     $backgroundImage->file_id = $file->id;
     if (!$backgroundImage->save()) {
         abort(403, $backgroundImage->errors);
     }
     return $backgroundImage;
 }
Example #15
0
 /**
  * Store a newly created resource in storage.
  *
  * @param FileUploadRequest $request
  * @return Response
  */
 public function postFilesCreate(FileUploadRequest $request)
 {
     $destinationPath = public_path() . '/uploads/files/';
     $file_temp = $request->file('file');
     $extension = $file_temp->getClientOriginalExtension() ?: 'png';
     $safeName = str_random(10) . '.' . $extension;
     $fileItem = new File();
     $fileItem->filename = $safeName;
     $fileItem->mime = $file_temp->getMimeType();
     $fileItem->save();
     $file_temp->move($destinationPath, $safeName);
     Thumbnail::generate_image_thumbnail($destinationPath . $safeName, $destinationPath . 'thumb_' . $safeName);
     $success = new stdClass();
     $success->name = $safeName;
     $success->size = $file_temp->getClientSize();
     $success->url = $safeName;
     $success->thumbnailUrl = URL::to('/uploads/files/thumb_' . $safeName);
     $success->deleteUrl = URL::to('admin/file/delete?_token=' . csrf_token() . '&id=' . $fileItem->id);
     $success->deleteType = 'DELETE';
     $success->fileID = $fileItem->id;
     return Response::json(array('files' => array($success)), 200);
 }
Example #16
0
 private function handleFile($root_folder, $f)
 {
     /*
     	The "black" identifier is just an abstract reference, not a real file:
     	we skip analysis for it
     */
     if ($f == 'black') {
         return true;
     }
     /*
     	This is to manage eventual files embedded multiple times: we track only
     	one, and eventually will substitute once all occurrences in the mlt file
     	when required
     */
     $path = $this->guessPath($root_folder, $f);
     $test_count = File::where('project_id', '=', $this->project->id)->where('original_path', '=', $path)->first();
     if ($test_count != null) {
         $test_count->references = $test_count->references + 1;
         $test_count->save();
         return true;
     }
     $file = new File();
     $file->project_id = $this->project->id;
     $file->filename = basename($f);
     $file->original_path = $path;
     $file->references = 1;
     $ret = $file->testReach();
     $file->save();
     return $ret;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     //echo "string"; exit();
     $v = Validator::make(Request::all(), ['name' => 'required|max:50|unique:modeldesigns', 'hall_id' => 'required', 'exhibition_id' => 'required']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     } else {
         $exhibitionevent = new ExhibitionEvent();
         $exhibitionevent->name = Request::get('name');
         $exhibitionevent->desc = Request::get('desc');
         $exhibitionevent->start_time = Request::get('start_time');
         $exhibitionevent->end_time = Request::get('end_time');
         // $exhibitionevent->hall_id = Request::get('hall_id');
         $exhibitionevent->exhibition_id = Request::get('exhibition_id');
         $exhibitionevent->save();
         $exhibitioneventhall = new ExhibitionEventHall();
         $exhibitioneventhall->exhibition_event_id = $exhibitionevent->id;
         $exhibitioneventhall->hall_id = Request::get('hall_id');
         $exhibitioneventhall->save();
         // File Storage
         $file = new File();
         $file->name = Request::get('filename');
         $file->desc = Request::get('filedesc');
         $file->type = Request::get('filetype');
         if (Request::hasFile('file')) {
             $destination = 'files/';
             $filename = str_random(6) . "_" . Request::file('file')->getClientOriginalName();
             Request::file('file')->move($destination, $filename);
             $file->file = $filename;
         } else {
             $file->file = Request::get('file');
         }
         $file->save();
         $exhibitioneventfile = new ExhibitionEventFile();
         $exhibitioneventfile->exhibition_event_id = $exhibitionevent->id;
         $exhibitioneventfile->file_id = $file->id;
         $exhibitioneventfile->save();
         return redirect('exhibitionevents');
     }
 }
Example #18
0
 /**
  * upload avatar
  * @param $file
  * @param $user_id
  * @return mixed
  */
 public static function saveAvatar($file, $user_id)
 {
     $now_date = str_replace('/', '_', date('d/m/Y'));
     $filename = $file->getClientOriginalName();
     $filename = File::removesign($filename);
     $filename = File::removespace($filename);
     $newfilename = $now_date . '_' . rand(1, 99999) . '_' . $filename;
     Storage::put('avatar/' . $newfilename, file_get_contents($file->getRealPath()));
     //$upload_success = $file->move($destinationPath, $newfilename);
     $path = storage_path('uploads/avatar/' . $newfilename);
     $img = Image::make($path);
     // resize image instance
     $img->resize(320, 240);
     $savefile = new File(['name' => $newfilename, 'mine' => $file->getClientMimeType(), 'original_filename' => $file->getClientOriginalName(), 'nguoiupload_id' => $user_id]);
     $savefile->save();
     return $savefile->id;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $v = Validator::make(Request::all(), ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:6']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     } else {
         $user = new User();
         $user->name = Request::get('name');
         $user->email = Request::get('email');
         $user->type = Request::get('type');
         $user->password = bcrypt(Request::get('password'));
         $user->save();
         $gInfo = new Generalinfo();
         $gInfo->user_id = $user->id;
         $gInfo->save();
         $pInfo = new Professionalinfo();
         $pInfo->user_id = $user->id;
         $pInfo->save();
         $data['email'] = Request::get('email');
         $data['name'] = Request::get('name');
         // Mail::send('emails.welcome', $data, function($message) use ($data)
         //           {
         //               $message->from('*****@*****.**', "Wavexpo");
         //               $message->subject("Welcome to Wavexpo Please visit our website to continu you information");
         //               $message->to($data['email']);
         //           });
         //return redirect()->action('UserFilesController@store', [$user->id,]);
         // File Storage
         $file = new File();
         $file->name = Request::get('filename');
         $file->desc = Request::get('desc');
         $file->type = Request::get('filetype');
         if (Request::hasFile('file')) {
             $destination = 'files/';
             $filename = str_random(6) . "_" . Request::file('file')->getClientOriginalName();
             Request::file('file')->move($destination, $filename);
             $file->file = $filename;
         } else {
             $file->file = Request::get('file');
         }
         $file->save();
         $userfile = new UserFile();
         $userfile->user_id = $user->id;
         $userfile->file_id = $file->id;
         $userfile->save();
         return redirect('users');
     }
 }
 public function uploadImage(Request $request)
 {
     // file was uploaded successfully
     if ($request->hasFile('photo') && $request->file('photo')->isValid()) {
         // get file object
         $file = $request->file('photo');
         // separate extension and name
         $temp = explode('.', $file->getClientOriginalName());
         $ext = array_pop($temp);
         $name = implode('.', $temp);
         // slugify the name and lowercase the ext
         $fileName = Self::slugify($name) . '.' . strtolower($ext);
         $destinationPath = public_path('images/uploaded/');
         if (file_exists($destinationPath . DIRECTORY_SEPARATOR . $fileName)) {
             $fileName = Self::slugify($name) . '-' . Self::generateRandomString(5) . '.' . strtolower($ext);
         }
         // move to correct folder
         $file->move($destinationPath, $fileName);
         $i = new File();
         $i->title = $request->input('title');
         $i->file = $fileName;
         $i->save();
     }
     return redirect('/dashboard/images');
 }
 public function postPoster(Request $request)
 {
     $poster = File::where('img_type', "poster")->where("created_at", "like", $this->year . "%")->first();
     $file = $request->file('poster');
     if ($request->hasFile('poster')) {
         if ($poster == null) {
             $sub = new File();
             $sub->name = Carbon::now()->timestamp . '_' . $file->getClientOriginalName();
             $sub->original_name = $file->getClientOriginalName();
             $sub->description = "Poster template";
             $sub->type = $file->getClientOriginalExtension();
             $sub->img_type = "poster";
             $sub->save();
         } else {
             $sub = File::where('img_type', "poster")->where("created_at", "like", $this->year . "%")->first();
             $sub->name = Carbon::now()->timestamp . '_' . $file->getClientOriginalName();
             $sub->original_name = $file->getClientOriginalName();
             $sub->description = "Poster template";
             $sub->type = $file->getClientOriginalExtension();
             $sub->img_type = "poster";
             $sub->save();
         }
         $file->move('assets/files', Carbon::now()->timestamp . '_' . $file->getClientOriginalName());
         return back()->with('success', 'file');
     } else {
         return "error upload";
     }
 }
Example #22
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function filehandle($req, $id)
 {
     // PDF tidak di update / melalui form
     // Gagal mengupload file PDF
     // Sukses Mengupload DOkumen
     $pesan = ['error' => ['Peringatan : File PDF tidak di atur dengan benar !', 'Terjadi kesalahan upload File PDf '], 'succes' => 'Sukses mengupload Dokumen PDF '];
     // dd($req->all());
     $file = $req->file('gambar');
     // $lokasi_tujuan=str_slug( str_replace('-', ' ', $req->get('no_boks')));
     $lokasi_tujuan = $req->get('no_boks');
     if ($file and $file->getClientMimeType() == 'application/pdf') {
         // dd($file);
         $extension = $file->getClientOriginalExtension();
         $entry = File::where('dokumen_id', '=', $id)->first();
         // format nama file = ==============================================================================================
         $nama_file = str_slug(str_replace('/', '-', $req->get('no_sppd'))) . '-' . str_slug(str_replace('/', '-', $req->get('nama_dokumen'))) . '-' . $file->getFilename() . '.' . $extension;
         // echo $nama_file;
         // dd($entry);
         if (count($entry)) {
             // dd(count($entry->get()->toArray()));
             // $entry=File::find($entry->id);
             // dd($entry->with('dokumen')->get());
             // dd($entry->get()->toArray()[0]['filename']);
             // if (\Storage::exists($entry->get()->toArray()[0]['dir'].'/'.$entry->get()->toArray()[0]['filename'])) {
             //     \Storage::delete($entry->get()->toArray()[0]['dir'].'/'.$entry->get()->toArray()[0]['filename']);
             //     }
             // if($entry){
             $lokasi_baru = $entry->dir . '/' . $entry->nama_baru;
             $lokasi_lama = $entry->filename;
             if ($entry->dir && $entry->nama_baru && \Storage::exists($lokasi_baru)) {
                 // echo $lokasi_baru;
                 \Storage::move($lokasi_baru, 'RecycleBin/' . $entry->nama_baru);
                 // \Storage::delete($lokasi_baru);
             }
             if ($entry->filename && \Storage::exists($lokasi_lama)) {
                 // echo $lokasi_lama;
                 \Storage::move($lokasi_lama, 'RecycleBin/' . $entry->nama_baru);
                 // \Storage::delete($lokasi_lama);
             }
             // dd($lokasi_baru);
             // $entry->delete();
             // }
             $update = ['mime' => $file->getClientMimeType(), 'original_filename' => $file->getClientOriginalName(), 'filename' => $nama_file, 'nama_baru' => $nama_file, 'dir' => $lokasi_tujuan];
             if ($entry->update($update)) {
                 $dirs = \Storage::allDirectories();
                 // $dir=str_slug( str_replace('-', ' ', $req->get('no_boks')));
                 $dir = $lokasi_tujuan;
                 if (!in_array($dir, $dirs)) {
                     \Storage::makeDirectory($lokasi_tujuan);
                 }
                 echo $nama_file;
                 \Storage::put($dir . '/' . $nama_file, \File::get($file));
                 return true;
             }
             return false;
         } else {
             $entry = new File();
             $entry->dokumen_id = $id;
             $entry->mime = $file->getClientMimeType();
             $entry->original_filename = $file->getClientOriginalName();
             $entry->filename = $nama_file;
             $entry->nama_baru = $nama_file;
             // $entry->dir = str_slug( $req->get('no_boks'), "-");
             $entry->dir = $lokasi_tujuan;
             if ($entry->save()) {
                 $dirs = \Storage::allDirectories();
                 // $dir=str_slug( str_replace('-', ' ', $req->get('no_boks')));
                 $dir = $lokasi_tujuan;
                 if (!in_array($dir, $dirs)) {
                     \Storage::makeDirectory($lokasi_tujuan);
                 }
                 echo $nama_file;
                 \Storage::put($dir . '/' . $nama_file, \File::get($file));
                 return true;
             }
             return false;
         }
         // }
     } else {
         // Handle file pdf
         //pINDAH DIREKTORI KARENA UPDATE NO BOX
         $entry = File::where('dokumen_id', '=', $id)->first();
         //JIKA NAMA dir dari file $entry !==  str_slug($req->boks)
         // $lokasi_tujuan=str_slug( str_replace('-', ' ', $req->get('no_boks')));
         if ($entry && $entry->dir !== $lokasi_tujuan) {
             $nama_file = str_slug(str_replace('/', '-', $req->get('no_sppd'))) . '-' . str_slug(str_replace('/', '-', $req->get('nama_dokumen'))) . '-' . $entry->filename;
             // $nama_file_baru= str_slug( str_replace('-', ' ', $req->get('no_sppd'))).'-'.str_slug( str_replace('-', ' ', $req->get('nama_dokumen'))).'-'.$entry->filename;
             // $entry->nama_baru=!empty($entry->nama_baru) ? $entry->nama_baru:str_replace('/', '-', $entry->dokumen->no_sppd).'-'.$entry->filename;
             $entry->nama_baru = !empty($entry->nama_baru) ? $entry->nama_baru : $nama_file;
             // $entry->nama_baru=str_replace('/', '-', $entry->dokumen->no_sppd).'-'.$entry->filename;
             // dd('lama masuk ');
             $lokasi_lama_file = $entry->dir . '/' . $entry->nama_baru;
             $lokasi_lama_lama_migrasi = $entry->filename;
             // echo "baru".$lokasi_baru;
             // echo "baru".$lokasi_lama;
             $lokasi_tujuan_and_file = $lokasi_tujuan . '/' . $entry->nama_baru;
             // handle file yang telah dimigrasi
             if (\Storage::exists($lokasi_lama_file)) {
                 //cek apakah lokasi baru sudah atau belum
                 $dirs = \Storage::allDirectories();
                 if (in_array($lokasi_tujuan, $dirs)) {
                     // dd('dir ada ');
                     \Storage::move($lokasi_lama_file, $lokasi_tujuan_and_file);
                     // return true;
                 } elseif (!in_array($lokasi_tujuan, $dirs)) {
                     // print_r($lokasi_tujuan);
                     // print_r($dirs);
                     // dd('dir tidak ada ');
                     \Storage::makeDirectory($lokasi_tujuan);
                     \Storage::move($lokasi_lama_file, $lokasi_tujuan_and_file);
                     // return true;
                 } else {
                     // return 'Adalah masalah permissi penulisan file Anda ';
                 }
                 //pindahkan file ke lokasi baru
                 //simpan nama lokasi baru
             } elseif (\Storage::exists($lokasi_lama_lama_migrasi)) {
                 //cek apakah lokasi baru sudah atau belum
                 $dirs = \Storage::allDirectories();
                 // Lokasi telah siap
                 if (in_array($lokasi_tujuan, $dirs)) {
                     \Storage::move($lokasi_lama_lama_migrasi, $lokasi_tujuan_and_file);
                     // return true;
                 }
                 if (!in_array($lokasi_tujuan, $dirs)) {
                     \Storage::makeDirectory($lokasi_tujuan);
                     \Storage::move($lokasi_lama_lama_migrasi, $lokasi_tujuan_and_file);
                     // return true;
                 } else {
                     // return 'Adalah masalah permissi penulisan file Anda ';
                 }
                 //pindahkan file ke lokasi baru
                 //simpan nama lokasi baru
             } else {
                 echo 'File lama tidak ada!!!!';
                 return false;
             }
             $entry->dir = $lokasi_tujuan;
             // dd($lokasi_tujuan);
             if ($entry->save()) {
                 echo 'Telah diupdate Ke Lokasi baru';
                 return true;
             }
         }
         // Handle db file
         // $update= $entry;
         // ['mime' => $file->getClientMimeType(),
         //                  'original_filename' => $file->getClientOriginalName(),
         //                  'filename' =>$nama_file,
         //                  'nama_baru' =>$nama_file,
         //                  'dir' =>str_slug( $req->get('no_boks'), "-"),
         //                  ];
         // $data['msg']='Gagal';
         // // $data['errors']=$errors;
         // $data['errors']='File yang anda Upload bukan PDF';
         // $data['code']=403;
         // // echo json_encode($data);
         // return \Response::make(json_encode($data), 403);
         return false;
         // return 'File yang anda Upload bukan PDF';
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $v = Validator::make(Request::all(), ['name' => 'required|max:50|unique:halls', 'type_id' => 'required', 'modeldesign_id' => 'required', 'exhibitor' => 'required', 'exhibitionevent' => 'required']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     } else {
         $booth = new Booth();
         $booth->name = Request::get('name');
         $booth->desc = Request::get('desc');
         $booth->type_id = Request::get('type_id');
         $booth->modeldesign_id = Request::get('modeldesign_id');
         $booth->exhibitor_id = Request::get('exhibitor');
         $booth->exhibition_event_id = Request::get('exhibitionevent');
         $booth->spot_id = Request::get('spot_id');
         $booth->save();
         // File Storage
         $file = new File();
         $file->name = Request::get('filename');
         $file->desc = Request::get('filedesc');
         $file->type = Request::get('filetype');
         if (Request::hasFile('file')) {
             $destination = 'files/';
             $filename = str_random(6) . "_" . Request::file('file')->getClientOriginalName();
             Request::file('file')->move($destination, $filename);
             $file->file = $filename;
         } else {
             $file->file = Request::get('file');
         }
         $file->save();
         $boothfile = new BoothFile();
         $boothfile->booth_id = $booth->id;
         $boothfile->file_id = $file->id;
         $boothfile->save();
         return redirect('booths');
     }
 }
 public function postSubmission()
 {
     if (Input::hasFile('images')) {
         foreach (Input::file('images') as $image) {
             $randomString = str_random();
         }
         $filename = $randomString . '.jpg';
         $path = public_path('assets/images/submission');
         $image->move($path, $filename);
         $file = new File();
         $file->name = $randomString;
         $file->original_name = $image->getClientOriginalName();
         $file->description = "Submission Image";
         $file->type = 'jpg';
         $file->img_type = "submission";
         $file->save();
         return response()->json(array('path' => $path), 200);
     } else {
         return response()->json(false, 200);
     }
 }
 public function storecompanybyadmin()
 {
     $v = Validator::make(Request::all(), ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:6']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     } else {
         $user = new User();
         $user->name = Request::get('name');
         $user->email = Request::get('email');
         $user->type = 'companyuuuuuu';
         $user->password = bcrypt(Request::get('password'));
         $user->save();
         $company = new Company();
         //$userId=Auth::user()->id;
         $company->user_id = $user->id;
         $company->country_id = Request::get('country');
         $company->city = Request::get('city');
         $company->logo = Request::get('company');
         $company->address = Request::get('address');
         $company->desc = Request::get('desc');
         $company->phone = Request::get('phone');
         $company->anotherphone = Request::get('anotherphone');
         $company->fax = Request::get('fax');
         $company->facebook = Request::get('facebook');
         $company->twitter = Request::get('twitter');
         $company->linkedIn = Request::get('linkedIn');
         $company->website = Request::get('website');
         $company->save();
         // Mail::send('emails.welcome', $data, function($message) use ($data)
         //           {
         //               $message->from('*****@*****.**', "Wavexpo");
         //               $message->subject("Welcome to Wavexpo Please visit our website to continu you information");
         //               $message->to($data['email']);
         //           });
         // File Storage
         $file = new File();
         $file->name = Request::get('filename');
         $file->desc = Request::get('filedesc');
         $file->type = Request::get('filetype');
         if (Request::hasFile('file')) {
             $destination = 'files/';
             $filename = str_random(6) . "_" . Request::file('file')->getClientOriginalName();
             Request::file('file')->move($destination, $filename);
             $file->file = $filename;
         } else {
             $file->file = Request::get('file');
         }
         $file->save();
         $userfile = new CompanyFile();
         $userfile->company_id = $company->id;
         $userfile->file_id = $file->id;
         $userfile->save();
         return redirect('users');
         return redirect('companies');
     }
 }
Example #26
0
Route::resource('api/contact', 'ContactsController');
Route::get('api/user', function () {
    $user = Auth::user();
    return $user;
});
Route::resource('api/file', 'FilesController');
//Upload Avatars
Route::post('avatar/upload/{id}', function (Request $request, $id) {
    $contact = Contact::find($id);
    $fileName = date('U') . $contact->id . '.jpg';
    $request->file('file')->move(public_path('assets/img/avatars'), $fileName);
    $contact->avatar = $fileName;
    $contact->save();
    return $contact;
});
//Upload Files
Route::post('file/upload/{id}', function (Request $request, $id) {
    $file = new File();
    $contact = Contact::find($id);
    $file->contact_id = $id;
    $folder = public_path('assets/files/' . $contact->name);
    if (is_dir($folder) == false) {
        mkdir($folder);
    }
    $uploadedFile = $request->file('file');
    $fileName = $uploadedFile->getClientOriginalName();
    $uploadedFile->move($folder, $fileName);
    $file->name = $fileName;
    $file->save();
    return $file;
});
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     //echo "string"; exit();
     $v = Validator::make(Request::all(), ['name' => 'required|max:50|unique:exhibitors']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     } else {
         $exhibition = new Exhibition();
         $exhibition->name = Request::get('name');
         $exhibition->desc = Request::get('desc');
         $exhibition->save();
         // File Storage
         $file = new File();
         $file->name = Request::get('filename');
         $file->desc = Request::get('filedesc');
         $file->type = Request::get('filetype');
         if (Request::hasFile('file')) {
             $destination = 'files/';
             $filename = str_random(6) . "_" . Request::file('file')->getClientOriginalName();
             Request::file('file')->move($destination, $filename);
             $file->file = $filename;
         } else {
             $file->file = Request::get('file');
         }
         $file->save();
         $userfile = new ExhibitionFile();
         $userfile->exhibition_id = $exhibition->id;
         $userfile->file_id = $file->id;
         $userfile->save();
         return redirect('exhibitions');
     }
 }
 public function storeexhibitorbyadmin()
 {
     $v = Validator::make(Request::all(), ['name' => 'required|max:50', 'company' => 'required']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     } else {
         $exhibitor = new Exhibitor();
         $exhibitor->company_id = Request::get('company');
         $exhibitor->country_id = Request::get('country');
         $exhibitor->city = Request::get('city');
         $exhibitor->address = Request::get('address');
         $exhibitor->name = Request::get('name');
         $exhibitor->desc = Request::get('desc');
         $exhibitor->phone = Request::get('phone');
         $exhibitor->anotherphone = Request::get('anotherphone');
         $exhibitor->fax = Request::get('fax');
         $exhibitor->save();
         // File Storage
         $file = new File();
         $file->name = Request::get('filename');
         $file->desc = Request::get('filedesc');
         $file->type = Request::get('filetype');
         if (Request::hasFile('file')) {
             $destination = 'files/';
             $filename = str_random(6) . "_" . Request::file('file')->getClientOriginalName();
             Request::file('file')->move($destination, $filename);
             $file->file = $filename;
         } else {
             $file->file = Request::get('file');
         }
         $file->save();
         $exhibitorfile = new ExhibitorFile();
         $exhibitorfile->exhibitor_id = $exhibitor->id;
         $exhibitorfile->file_id = $file->id;
         $exhibitorfile->save();
         // Admin
         if ($this->adminAuth()) {
             return redirect('exhibitors');
         }
         //Company
         $user = User::find(Auth::User()->id);
         $company = Company::where('user_id', $user->id)->get();
         $company = $company[0];
         $companyId = $company->id;
         $exhibitors = Exhibitor::where('company_id', $companyId)->get();
         return view('companies.listallexhibitorsofCompany', compact('exhibitors'));
     }
 }
Example #29
-1
 /**
  * Can't update most of the fields once they have been verified, only email/password/pubilc.
  *
  * @param  User   		$user
  * @return Response
  */
 public function update(User $user, Request $request)
 {
     if ($user->id != Auth::user()->id && !Auth::user()->can('administrate-users')) {
         abort(401, 'You do not have permission to edit this user');
     }
     //If the user has the authentication level, they can change some things
     $user->secureFill($request->except('token'));
     if (!$user->save()) {
         //Validation failed
         abort(400, $user->errors);
     }
     if ($request->file('government_identification')) {
         $file = new File();
         $file->uploadFile('government_identification', 'government_identification', $request);
         if (!$file->save()) {
             abort(403, $file->errors);
         }
         $user->government_identification_id = $file->id;
     }
     if ($request->file('avatar')) {
         $file = new File();
         $file->uploadFile('avatars', 'avatar', $request);
         if (!$file->save()) {
             abort(403, $file->errors);
         }
         $user->government_identification_id = $file->id;
     }
     $user->save();
     return $user;
 }
Example #30
-1
 public static function saveFileByFileContent($fileContent, $fileName, $mimeType, User $user, $diskName = null)
 {
     $rootDir = "uploaded-file";
     $fs = Storage::disk($diskName);
     $md5 = md5($fileContent);
     $sha1 = sha1($fileContent);
     $size = strlen($fileContent);
     $diskName = $diskName ? $diskName : Storage::getDefaultDriver();
     $name = $fileName;
     $ext = File::extension($fileName);
     $now = Carbon::now();
     $toDirPath = $rootDir . '/' . $now->year . '/' . $now->month . '/' . $now->day;
     $toFilePath = $toDirPath . '/' . $md5 . '-' . $sha1;
     try {
         $fs->makeDirectory($toDirPath);
     } catch (\Exception $e) {
         if (!$fs->exists($toDirPath)) {
             throw $e;
         }
     }
     if (!$fs->exists($toFilePath)) {
         $fs->put($toFilePath, $fileContent);
     }
     $basicFile = BasicFile::where('md5', $md5)->where('sha1', $sha1)->where('size', $size)->first();
     if (!$basicFile) {
         $basicFile = new BasicFile();
         $basicFile->md5 = $md5;
         $basicFile->sha1 = $sha1;
         $basicFile->size = $size;
         $basicFile->disk = $diskName;
         $basicFile->path = $toFilePath;
         $basicFile->save();
     }
     $fileModel = new FileModel();
     $fileModel->name = $name;
     $fileModel->ext = $ext;
     $fileModel->mime = $mimeType;
     $fileModel->user()->associate($user);
     $fileModel->baseFile()->associate($basicFile);
     $fileModel->save();
     return $fileModel;
 }