/** * Store a newly created resource in storage. * * @param StoreMediaRequest $request * @return Response */ public function store(StoreMediaRequest $request) { if ($request->ajax()) { $response = ['error' => 1, 'path' => '']; if ($request->hasFile('file')) { $file = $request->file('file'); $folder = '/public/uploads/' . $request->folder; if (!\Storage::exists($folder)) { \Storage::makeDirectory($folder); } $path = $folder . '/' . date('Y-m-d'); $hashed = sha1(Str::slug($file->getClientOriginalName() . time())) . '.' . $file->getClientOriginalExtension(); if (!\Storage::exists($path)) { \Storage::makeDirectory($path); } if ($file->move(storage_path('app') . $path, $hashed)) { $path = str_replace('/public', '', $path); $medium = $this->medium->create(['path' => $path . '/' . $hashed]); if ($medium) { $response['error'] = 0; $response['path'] = $path . '/' . $hashed; return response($response, 200); } // TODO: ln -s storage/app/public/uploads /path/to/public_html/public } } } return response('error', 400); }
/** * Checks if the Database Directory exists, * if not, directory will be created. */ private function checkDirectoryExists() { $directory = storage_path($this->directoryPath); if (!$this->storage->exists($directory)) { $this->storage->makeDirectory($directory); } }
/** * @param UploadedFile $file * @return string */ protected function moveToLocalStorage($file) { if (!file_exists(storage_path('app/doctor-information'))) { \Storage::makeDirectory('doctor-information'); } $disk_filename = Carbon::now()->format('YmdHis') . '.' . $file->getClientOriginalExtension(); $file->move(storage_path('app/doctor-information'), $disk_filename); return $disk_filename; }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('users')->insert(['username' => 'aldi.fahrezi', 'fullname' => 'Aldi Fahrezi', 'email' => '*****@*****.**', 'birthday' => '1997-09-08', 'role_id' => 2, 'voted_threads' => "|", 'voted_replies' => "|"]); for ($count = 0; $count < 5; $count++) { DB::table('users')->insert(['username' => str_random(10) . $count, 'fullname' => str_random(10) . $count, 'email' => str_random(10) . '@gmail.com', 'birthday' => rand(1611, 2014) . '-' . rand(10, 12) . '-' . rand(10, 30), 'voted_threads' => "|", 'voted_replies' => "|"]); } for ($count = 1; $count <= 50; $count++) { Storage::makeDirectory('users/' . $count); } }
private function crearCarpeta() { //Si no existe: genera carpeta y obtiene carpeta_id $carpeta = new Carpeta(); $carpeta->save(); \Storage::makeDirectory($carpeta->id); //Relacionar Carpeta-Dcoumento $carpeta_documento = new CarpetaDocumento(['carpeta_id' => $carpeta->id, 'documento_id' => $this->documento_id, 'documento_type' => $this->documento_type]); $carpeta->documentos()->save($carpeta_documento); return $carpeta->id; }
/** * Upload image via Image library * * @param $file * @param string $upload_path * @return string */ public function uploadImage($file, $upload_path = '/') { $this->setPath($upload_path); if (!is_dir($this->path)) { \Storage::makeDirectory($this->path); } $this->setFileName($file); $img = \Image::make($file)->save($this->getPath() . '/' . $this->getFileName(), 100); $this->fullpath = $this->getPath() . '/' . $this->getFileName(); $this->width = $img->width(); $this->height = $img->height(); return $this->getPath() . '/' . $this->getFileName(); }
/** * Execute the job. * * @return void */ public function handle() { $this->packageDir = $this->input['root'] . '/' . $this->input['vendor'] . '/' . $this->input['package']; $this->modelDir = $this->packageDir . '/src/' . ucfirst($this->input['models']); $this->model = $this->input['model']; $this->models = $this->input['models']; \Storage::makeDirectory($this->packageDir); $this->recurse_copy(__DIR__ . '/TemplateModel', $this->packageDir); $this->setFiles(); $this->changeFilenames(); $this->updateFiles($this->input['vendor'], $this->input['package']); dd('sdsds'); }
public function postUploadImage(Request $request, Guard $auth) { $pathUser = '******'; \Storage::makeDirectory($pathUser); $Documento = $request->file('file'); $nombre = $Documento->getClientOriginalName(); $fullPath = $pathUser . '/' . $nombre; $noticiaImg = NoticiasImg::firstOrNew(['path' => $fullPath]); $noticiaImg->nombre = $nombre; $noticiaImg->autor = $auth->id(); $noticiaImg->save(); \Storage::disk('local')->put($fullPath, \File::get($Documento)); return response()->json(['link' => '/documentos/' . $fullPath]); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function postCreate(Request $request) { $file = $request->file('avatar')->isValid(); echo $file; $fileName = $request->input('avatar'); // $slogan = \Request::input('slogan'); // $userInfo = array( // 'file' => $file, // 'slogan' => $slogan // ); //Check if Folder exists $folderName = date('Ymd'); if (!\Storage::disk('local')->exists($folderName)) { \Storage::makeDirectory($folderName); } //Check Validation //$fileName = $file->getClientOriginalName(); //Save it to Folder // \Storage::disk('local')->put($fileName,$file); // \Storage::move($fileName,$folderName.'/'.$fileName); // if(\Request::hasFile('avatar')){ // //Check if Folder exists // $folderName = date('Ymd'); // if(!Storage::disk('local')->exists($folderName)){ // Storage::makeDirectory($folderName); // } // //Get input File // $file = \Request::file('avatar'); // //Check Validation // $fileName = $file->getClientOriginalName(); // if(!$file->isValid()){ // return [$fileName => 'success']; // } // //Save it to Folder // Storage::disk('local')->put($fileName,$file); // Storage::move($fileName,$folderName.'/'.$fileName); // }else{ // echo 'weiba'; // } /* $user = \Auth::user(); $validator = Validator::make($userInfo,ValidRule::$phone_login_rules,ValidRule::$phone_login_tips); if($validator->passes()){ }else{ return \Redirect::to('login')->withErrors($validator); } */ }
public function postUploadImage(Request $request, Guard $auth) { $postulante = Postulante::where('user_id', $auth->id())->first(); $pathUser = '******'; \Storage::makeDirectory($pathUser); $Documento = $request->file('file'); $nombre = $Documento->getClientOriginalName(); $fullPath = $pathUser . '/' . $nombre; $docAdjunto = DocumentoAdjunto::firstOrNew(['path' => $fullPath]); $docAdjunto->nombre = $nombre; $docAdjunto->postulante = $postulante->id; $docAdjunto->save(); \Storage::disk('local')->put($fullPath, \File::get($Documento)); return response()->json(['link' => '/documentos/' . $fullPath]); }
public function postUploadDocAdmin(Request $request) { $pathUser = '******' . $request->get("id_postulante") . "/admin"; \Storage::makeDirectory($pathUser); if ($request->hasFile("cartaF1")) { $archivo = $request->file('cartaF1'); $temp = "carta de aceptación"; } else { $archivo = $request->file('cartaF2'); $temp = "Resolución de pregrado"; } $nombre = \Hash::make($archivo->getClientOriginalName()); $nombre = str_replace('/', 'Y', $nombre); $nombre = $nombre . '.' . $archivo->guessExtension(); $fullPath = $pathUser . '/' . $nombre; $docAdjunto = DocumentoAdjunto::firstOrNew(['path' => $fullPath]); $docAdjunto->nombre = $temp; $docAdjunto->postulante = $request->get("id_postulante"); $docAdjunto->save(); \Storage::disk('local')->put($fullPath, \File::get($archivo)); }
/** * Uplaod Image on Storage * * @param File $file * @param $key * * @return string */ function upload_photo_on_storage(File $file, $key) { if (!$file->isValid() || !$key) { return null; } $imageDirectory = 'images/profile'; if (!Storage::has($imageDirectory)) { Storage::makeDirectory($imageDirectory, 0777); } $imageExtension = $file->getClientOriginalExtension(); $imageHashName = $key; $imageFilePath = "app/{$imageDirectory}/{$imageHashName}"; $imageFileAbsolutePath = storage_path($imageFilePath); // resize image $image = Image::make($file->getRealPath())->resize(300, 300, function ($constraint) { // prevent possible upsizing $constraint->aspectRatio(); $constraint->upsize(); })->save($imageFileAbsolutePath); return $image ? $imageFilePath : null; }
/** * 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'; } }
/** * guarda un archivo en nuestro directorio local. * * @return Response */ public function save(Request $request) { // dd(Session::get('dni')); //obtenemos el campo file definido en el formulario \Storage::makeDirectory(Session::get('dni'), 0777); $file1 = $request->file('file1'); if ($file1 != null) { //obtenemos el nombre del archivo $nombre = Session::get('dni') . "/" . $file1->getClientOriginalName(); //indicamos que queremos guardar un nuevo archivo en el disco local \Storage::disk('local')->put($nombre, \File::get($file1)); } //obtenemos el campo file definido en el formulario $file2 = $request->file('file2'); if ($file2 != null) { //obtenemos el nombre del archivo $nombre = Session::get('dni') . "/" . $file2->getClientOriginalName(); //indicamos que queremos guardar un nuevo archivo en el disco local \Storage::disk('local')->put($nombre, \File::get($file2)); } //obtenemos el campo file definido en el formulario $file3 = $request->file('file3'); if ($file3 != null) { //obtenemos el nombre del archivo $nombre = Session::get('dni') . "/" . $file3->getClientOriginalName(); //indicamos que queremos guardar un nuevo archivo en el disco local \Storage::disk('local')->put($nombre, \File::get($file3)); } Session::forget('dni'); Session::flash('file_success', 'Los archivos fueron enviados correctamente!'); Session::flash('alert-class', 'alert-success'); return redirect()->back(); }
public function postStorageFiles(Request $request, Guard $auth) { /* $postulante = Postulante::where('user_id',$auth->id())->first(); $Documentos = $request->file('documentosAdjuntos'); $count = 0; $destino_path = public_path().'\documentos\postulante_'.$postulante->id; foreach($Documentos as $archivo) { $url_imagen = \Hash::make($archivo->getClientOriginalName()); $path_file = $url_imagen.'.'.$archivo->guessExtension(); //$path_file = str_replace('/', '0', $path_file); $subir = $archivo->move($destino_path, $destino_path); dd($path_file); //dd($url_imagen.'__________'.$path_file); $nombre_input = $request->get('new_'.$count); $docAdjunto = DocumentoAdjunto::firstOrNew(['nombre' => $nombre_input,'postulante'=>$postulante->id]);; $docAdjunto->path = $path_file; $docAdjunto->save(); $count++; } return response()->json([ 'message'=> 'Conexión realizada ctm' ]);*/ $postulante = Postulante::where('user_id', $auth->id())->first(); $pathUser = '******' . $postulante->id; \Storage::makeDirectory($pathUser); $Documentos = $request->file('documentosAdjuntos'); $count = 0; foreach ($Documentos as $archivo) { $nombre = \Hash::make($archivo->getClientOriginalName()); $nombre = str_replace('/', 'Y', $nombre); $nombre = $nombre . '.' . $archivo->guessExtension(); $nombre_input = $request->get('new_' . $count); $fullPath = $pathUser . '/' . $nombre; $docAdjunto = DocumentoAdjunto::firstOrNew(['path' => $fullPath]); $docAdjunto->nombre = $nombre_input; $docAdjunto->postulante = $postulante->id; $docAdjunto->save(); \Storage::disk('local')->put($fullPath, \File::get($archivo)); $count++; } return response()->json(['message' => 'Conexión realizada ctm']); }
public function updateProfile(UserRequest $request, Guard $auth) { $pathUser = '******'; \Storage::makeDirectory($pathUser); $user = User::findOrFail($auth->id()); $user->fill($request->all()); if ($request->hasFile('avatar')) { $Documento = $request->file('avatar'); $nombre = \Hash::make($Documento->getClientOriginalName()); $nombre = str_replace('/', 'Y', $nombre); $nombre = $nombre . '.' . $Documento->guessExtension(); $fullPath = $pathUser . '/' . $nombre; \Storage::disk('local')->put($fullPath, \File::get($Documento)); $user->avatar = 'documentos/' . $fullPath; } else { if ($request->get('delImgProfile') === 'true') { $user->avatar = 'avatar.jpg'; } } $user->save(); return redirect('home'); }