public function start(Request $request) { $this->validate($request, ['entity' => 'required|integer|between:1,6', 'file' => 'required']); $file = $request->file('file'); $path = $file->move('uploads', str_random(16) . time() . '.csv'); $entity = $request->input('entity'); switch ($entity) { case 1: $this->importStudents($path); break; case 2: $this->importProfessors($path); break; case 3: $this->importModules($path); break; case 4: $this->importCourses($path); break; case 5: $this->importGroups($path); break; case 6: $this->importEvents($path); break; } File::delete($file); return redirect()->back(); }
public static function boot() { parent::boot(); ProductLine::deleting(function ($productLine) { File::delete($productLine->image); }); }
public static function boot() { parent::boot(); ProductColor::deleting(function ($productColor) { File::delete($productColor->image); }); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'name' => 'max:100']); if ($validator->fails()) { return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput(); } if (Input::file('file')->isValid()) { $filePath = date('Ymd_His') . '.pdf'; if (Input::file('file')->move(base_path() . '/public/uploads/Announces/Announce-' . $request->get('year'), $filePath)) { //example of delete exist file $announceList = Announce::all(); if (sizeof($announceList) != 0) { $lastAnnounce = $announceList[sizeof($announceList) - 1]; $filename = base_path() . '/public/uploads/Announces/Announce-/' . $request->get('year') . '/' . $lastAnnounce->file_path; if (File::exists($filename)) { File::delete($filename); } // $oldAnnounce = Announce::findOrNew($lastAnnounce->id); $lastAnnounce = DB::table('announces')->where('year', $request->get('year'))->first(); // dd($lastAnnounce);die; if ($lastAnnounce != null) { Announce::destroy($lastAnnounce->id); } } $announce = new Announce(); $announce->file_path = $filePath; $announce->year = $request->get('year'); $announce->save(); return redirect('/announces'); } else { return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']); } } }
public static function boot() { parent::boot(); CourseGalleryItem::deleting(function ($courseGalleryItem) { File::delete($courseGalleryItem->image); }); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'name' => 'max:100']); if ($validator->fails()) { return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput(); } $riskManagements = RiskManagement::where('year', '=', $request->get('year'))->where('period', '=', $request->get('period'))->get(); if (sizeof($riskManagements) > 0) { foreach ($riskManagements as $riskManagement) { $filename = base_path() . '/public/uploads/Risk-Management/' . $request->get('year') . '/' . $request->get('period') . '/' . $riskManagement->file_path; if (File::exists($filename)) { File::delete($filename); } RiskManagement::destroy($riskManagement->id); } } if (Input::file('file')->isValid()) { $filePath = date('Ymd_His') . '.pdf'; if (Input::file('file')->move(base_path() . '/public/uploads/Risk-Management/' . $request->get('year') . '/' . $request->get('period'), $filePath)) { //example of delete exist file $riskManagement = new RiskManagement(); $riskManagement->file_path = $filePath; $riskManagement->year = $request->get('year'); $riskManagement->period = $request->get('period'); $riskManagement->save(); return redirect('/admin/management'); } else { return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']); } } }
public function putEdit(Request $request) { if (!ACL::hasPermission('awards', 'edit')) { return redirect(route('awards'))->withErrors(['Você não pode editar os prêmios.']); } $this->validate($request, ['title' => 'required|max:45', 'warning' => 'required', 'image' => 'image|mimes:jpeg,bmp,gif,png'], ['title.required' => 'Informe o título do prêmio', 'title.max' => 'O título do prêmio não pode passar de :max caracteres', 'warning.required' => 'Informe o aviso sobre o prêmio', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formato suportado: .png com fundo transparente']); $award = Awards::find($request->awardsId); $award->title = $request->title; $award->warning = $request->warning; if ($request->image) { //DELETE OLD IMAGE if ($request->currentImage != "") { if (File::exists($this->folder . $request->currentImage)) { File::delete($this->folder . $request->currentImage); } } $extension = $request->image->getClientOriginalExtension(); $nameImage = Carbon::now()->format('YmdHis') . "." . $extension; Image::make($request->file('image'))->resize($this->imageWidth, $this->imageHeight)->save($this->folder . $nameImage); $award->image = $nameImage; } $award->save(); $success = "Prêmio editado com sucesso"; return redirect(route('awards'))->with(compact('success')); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store($image, $type, $primary_id, $current_link) { $image_link = array_key_exists($type, Input::all()) ? Input::file($type) != '' ? '/allgifted-images/' . $type . '/' . $primary_id . '.' . $image->getClientOriginalExtension() : $current_link : $current_link; array_key_exists($type, Input::all()) ? File::exists(public_path($image_link)) ? File::delete(public_path($image_link)) : null : null; $image ? Image::make($image)->fit(500, 300)->save(public_path($image_link)) : null; return $image_link; }
public static function boot() { parent::boot(); RegionWorkshop::deleting(function ($regionWorkshop) { File::delete($regionWorkshop->image); }); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { if (Input::file()) { $profile = $this->profile->find($this->user->profile->id); $old = $profile->avatar; $path = public_path() . '/images/profiles/' . $old; if (File::exists($path)) { File::delete($path); } } $file = $request->file('file'); $filename = str_random(30) . time() . date('dmY') . '.' . $file->getClientOriginalExtension(); $file->move('images/profiles', $filename); dd(); // save profile pic if (Input::file()) { $profile = $this->profile->find($this->user->profile->id); $old = $profile->avatar; $path = public_path() . '/images/profiles/' . $old; if (File::exists($path)) { File::delete($path); } $string = str_random(30); $image = Input::file('image'); $filename = $string . time() . date('dmY') . '.' . $image->getClientOriginalExtension(); $path = public_path('/images/profiles/' . $filename); Image::make($image->getRealPath())->resize(200, null, function ($constraint) { $constraint->aspectRatio(); })->save($path, 60); $profile->avatar = $filename; $profile->save(); return redirect()->route('profiles.index'); } }
public static function boot() { parent::boot(); MainPageSlide::deleting(function ($mainPageSlide) { File::delete($mainPageSlide->image); }); }
/** * Execute the console command. */ public function fire() { $this->line(''); $this->info('Routes file: app/routes.php'); $message = 'This will rebuild routes.php with all of the packages that' . ' subscribe to the `toolbox.routes` event.'; $this->comment($message); $this->line(''); if ($this->confirm('Proceed with the rebuild? [Yes|no]')) { $this->line(''); $this->info('Backing up routes.php ...'); // Remove the last backup if it exists if (File::exists('app/routes.bak.php')) { File::delete('app/routes.bak.php'); } // Back up the existing file if (File::exists('app/routes.php')) { File::move('app/routes.php', 'app/routes.bak.php'); } // Generate new routes $this->info('Generating routes...'); $routes = Event::fire('toolbox.routes'); // Save new file $this->info('Saving new routes.php...'); if ($routes && !empty($routes)) { $routes = $this->getHeader() . implode("\n", $routes); File::put('app/routes.php', $routes); $this->info('Process completed!'); } else { $this->error('Nothing to save!'); } // Done! $this->line(''); } }
public function destroy($id) { $this->wish = Wish::find($id); File::delete(public_path('img/wishes/') . $this->wish->picture); $this->wish->delete(); return $this->getWishes(); }
/** * Store a newly created resource in storage. * * @param TemplateRequest $request * @return Response */ public function store(TemplateRequest $request) { ini_set('max_execution_time', 0); File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); $file_path = storage_path('tmp/'); $orginal_name = $request->file('file')->getClientOriginalName(); if ($request->file('file')->move($file_path, $orginal_name)) { Zipper::make($file_path . $orginal_name)->extractTo(storage_path('tmp')); $template = (require_once storage_path('tmp/Template.php')); $assets = File::move(storage_path('tmp/assets/' . $template['folder']), public_path('assets/' . $template['folder'])); $template_file = File::move(storage_path('tmp/' . $template['folder']), base_path('resources/views/' . $template['folder'])); if (!$assets || !$template_file) { File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); Flash::error('Tema Dosyası Yüklendi ama Dizinler Tasinamadi! Tüm İşlemleriniz İptal Edildi.'); return redirect()->route('admin.template.index'); } $message = $this->template->create($template) ? ['success', 'Başarıyla Kaydedildi'] : ['error', 'Bir Hata Meydana Geldi ve Kaydedilemedi']; File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); Flash::$message[0]($message[1]); if ($message[0] == "success") { Logs::add('process', "Şablon Eklendi\n{$template['name']}"); } else { Logs::add('errors', "Şablon Eklenemedi!"); } return redirect()->route('admin.template.index'); } }
public function putEdit(Request $request) { if (!ACL::hasPermission('winners2014', 'edit')) { return redirect(route('winners2014'))->withErrors(['Você não pode editar os ganhadores de 2014.']); } $this->validate($request, ['category' => 'required', 'position' => 'required', 'name' => 'required|max:50', 'city' => 'required|max:45', 'state' => 'required|max:2|min:2', 'quantityVotes' => 'required|numeric', 'image' => 'image|mimes:jpeg,bmp,gif,png'], ['category.required' => 'Escolha a categoria', 'position.required' => 'Escolha a posição', 'name.required' => 'Informe o nome do ganhador', 'name.max' => 'O nome do ganhador não pode passar de :max caracteres', 'city.required' => 'Informe o nome da cidade do ganhador', 'city.max' => 'O nome da cidade não pode passar de :max caracteres', 'state.required' => 'Informe o Estado do ganhador', 'state.max' => 'O UF do Estado deve ter apenas :max caracteres', 'state.min' => 'O UF do Estado deve ter apenas :min caracteres', 'quantityVotes.required' => 'Informe a quantidade de votos', 'quantityVotes.numeric' => 'Somente números são aceitos', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formatos suportados: .jpg, .gif, .bmp e .png']); $winner = WinnersLastYear::find($request->winnersLastYearId); $winner->category = $request->category; $winner->position = $request->position; $winner->name = $request->name; $winner->city = $request->city; $winner->state = $request->state; $winner->quantityVotes = $request->quantityVotes; if ($request->photo) { //DELETE OLD PHOTO if ($request->currentPhoto != "") { if (File::exists($this->folder . $request->currentPhoto)) { File::delete($this->folder . $request->currentPhoto); } } $extension = $request->photo->getClientOriginalExtension(); $namePhoto = Carbon::now()->format('YmdHis') . "." . $extension; $img = Image::make($request->file('photo')); if ($request->photoCropAreaW > 0 or $request->photoCropAreaH > 0 or $request->photoPositionX or $request->photoPositionY) { $img->crop($request->photoCropAreaW, $request->photoCropAreaH, $request->photoPositionX, $request->photoPositionY); } $img->resize($this->photoWidth, $this->photoHeight)->save($this->folder . $namePhoto); $winner->photo = $namePhoto; } $winner->save(); $success = "Ganhador editado com sucesso"; return redirect(route('winners2014'))->with(compact('success')); }
/** * Store a newly created resource in storage. * * @param TemplateRequest $request * @return Response */ public function store(TemplateRequest $request) { ini_set('max_execution_time', 0); File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); $file_path = storage_path('tmp/'); $orginal_name = $request->file('file')->getClientOriginalName(); if ($request->file('file')->move($file_path, $orginal_name)) { Zipper::make($file_path . $orginal_name)->extractTo(storage_path('tmp')); $template = (require_once storage_path('tmp/Template.php')); $assets = File::move(storage_path('tmp/assets/' . $template['folder']), public_path('assets/' . $template['folder'])); $template_file = File::move(storage_path('tmp/' . $template['folder']), base_path('resources/views/' . $template['folder'])); if (!$assets || !$template_file) { File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); Flash::error(trans('whole::http/controllers.templates_flash_1')); return redirect()->route('admin.template.index'); } $message = $this->template->create($template) ? ['success', trans('whole::http/controllers.templates_flash_2')] : ['error', trans('whole::http/controllers.templates_flash_3')]; File::delete(base_path('resources/views/Template.php')); File::delete(storage_path('tmp/Template.php')); File::deleteDirectory(storage_path('tmp/')); Flash::$message[0]($message[1]); if ($message[0] == "success") { Logs::add('process', trans('whole::http/controllers.templates_log_1', ['name' => $template['name']])); } else { Logs::add('errors', trans('whole::http/controllers.templates_log_2')); } return redirect()->route('admin.template.index'); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'name' => 'max:100']); if ($validator->fails()) { return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput(); } //example of delete exist file $existPlan = Plan::where('year', '=', $request->get('year'))->first(); if ($existPlan != null) { $filename = base_path() . '/public/uploads/Plans/Plan-' . $request->get('year') . '/' . $existPlan->file_path; //delete upload file if (File::exists($filename)) { File::delete($filename); } Plan::destroy($existPlan->id); } if (Input::file('file')->isValid()) { $filePath = date('Ymd_His') . '.pdf'; if (Input::file('file')->move(base_path() . '/public/uploads/Plans/Plan-' . $request->get('year'), $filePath)) { //add new file path in to databnase $plan = new Plan(); $plan->year = $request->get('year'); $plan->file_path = $filePath; $plan->save(); return redirect('/admin/management'); } else { return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']); } } }
/** * Execute the console command. * * @return mixed */ public function handle() { if (File::exists(Config::publishedSeederRealpath())) { if (!$this->confirm('The seeder file already exists, overwrite it? [Yes|no]')) { $this->line(''); return $this->info('Okay, no changes made to the file.'); } } // Laravel 5.0 does not have make:seed command // in that case ignore the command and copy the contents // of the file directly. try { $this->callSilent('make:seed', ['name' => Config::seederNameKey()]); } catch (\Exception $ex) { } $inputFile = file_get_contents(Config::localSeederPath()); $outputFile = fopen(Config::publishedSeederRealpath(), 'w'); if ($inputFile && $outputFile) { fwrite($outputFile, $inputFile); fclose($outputFile); } else { File::delete(Config::publishedSeederRealpath()); $this->line(''); return $this->error('There was an error creating the seeder file, ' . 'check write permissions for database/seeds directory' . PHP_EOL . PHP_EOL . 'If you think this is a bug, please submit a bug report ' . 'at https://github.com/moharrum/laravel-geoip-world-cities/issues'); } $this->line(''); $this->info('Okay, seeder file created successfully.'); }
public function delete() { foreach ($this->photos as $photo) { File::delete($photo->path); } parent::delete(); }
/** * Delete the file with the given path * * @param string $file * * @return boolean * @throws FileDoesNotExists */ public function fileDelete($file) { if (!File::isFile($this->getPath($file))) { throw new FileDoesNotExists(); } return File::delete($this->getPath($file)); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'year' => 'required', 'month' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput(); } if (Input::file('file')->isValid()) { //example of delete exist file $existCsrActivity = DB::table('csr_activities')->where('year', $request->get('year'))->where('month', $request->get('month'))->first(); if ($existCsrActivity != null) { $filename = base_path() . '/public/uploads/Csr-activities/' . $request->get('year') . '/' . $existCsrActivity->file_path; if (File::exists($filename)) { File::delete($filename); } CsrActivity::destroy($existCsrActivity->id); } $filePath = $request->get('month') . '.pdf'; if (Input::file('file')->move(base_path() . '/public/uploads/Csr-activities/' . $request->get('year'), $filePath)) { $csrActivity = new CsrActivity(); $csrActivity->file_path = $filePath; $csrActivity->month = $request->get('month'); $csrActivity->year = $request->get('year'); $csrActivity->save(); return redirect('/admin/management'); } else { return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']); } } }
public function saveCroppedImage(Request $request, $slider_title = "") { $file = $request->file('slider_img'); if ($file && isset($_FILES["slider_img"]["tmp_name"])) { try { $slider_img_x = $_POST['x']; $slider_img_y = $_POST['y']; $slider_img_w = $_POST['w']; $slider_img_h = $_POST['h']; $display_w = $_POST['display_w']; $file_path = $file->getPathname(); $orig_w = getimagesize($_FILES["slider_img"]["tmp_name"])[0]; $ratio = $orig_w / $display_w; $fileUploadDir = 'files/uploads/'; $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension(); if (File::exists($fileUploadDir . $fileName)) { $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension(); } $img = \Img::make($file_path)->crop((int) ($slider_img_w * $ratio), (int) ($slider_img_h * $ratio), (int) ($slider_img_x * $ratio), (int) ($slider_img_y * $ratio)); $img = $img->resize(300, 300); $tmpFile = $fileUploadDir . "tmp_slider_img" . time(); $img->save($tmpFile); //merge two images to one $this->merge('img/deze.png', $tmpFile, $fileUploadDir . $fileName, $slider_title, $request); //delete tmp file File::delete($tmpFile); return $fileName; } catch (Exception $e) { return false; } } return false; }
public static function boot() { parent::boot(); Article::deleting(function ($article) { File::delete($article->document); }); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'year' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput(); } //example of delete exist file $existMeetingReport = MeetingReport::where('year', '=', $request->get('year'))->where('no', '=', $request->get('no'))->first(); if ($existMeetingReport != null) { $filename = base_path() . '/public/uploads/Meeting-reports/' . $request->get('year') . '/' . $existMeetingReport->file_path; if (File::exists($filename)) { File::delete($filename); } MeetingReport::destroy($existMeetingReport->id); } if (Input::file('file')->isValid()) { $filePath = $request->get('no') . '.pdf'; if (Input::file('file')->move(base_path() . '/public/uploads/Meeting-reports/' . $request->get('year'), $filePath)) { $meetingReport = new MeetingReport(); $meetingReport->file_path = $filePath; $meetingReport->year = $request->get('year'); $meetingReport->no = $request->get('no'); $meetingReport->save(); return redirect('/admin/management'); } else { return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']); } } }
public static function boot() { parent::boot(); ProductCategory::deleting(function ($productTag) { File::delete($productTag->image); }); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['file' => 'mimes:pdf']); if ($validator->fails()) { return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput(); } $existBoardCommand = BoardCommand::all()->first(); if ($existBoardCommand != null) { $filename = base_path() . '/public/uploads/Commands/' . $existBoardCommand->file_path; if (File::exists($filename)) { File::delete($filename); } BoardCommand::destroy($existBoardCommand->id); } if (Input::file('file')->isValid()) { $filePath = 'board-command.pdf'; if (Input::file('file')->move(base_path() . '/public/uploads/Commands/', $filePath)) { //example of delete exist file $boardCommand = new BoardCommand(); $boardCommand->file_path = $filePath; $boardCommand->save(); return redirect('/admin/management'); } else { return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']); } } }
public function rmFile($filename) { $fileUploadDir = 'files/uploads/'; if (File::exists($fileUploadDir . $filename)) { File::delete($fileUploadDir . $filename); } }
/** * @return void */ public function fire() { $database = $this->getDatabase($this->input->getOption('database')); $this->checkDumpFolder(); //---------------- $dbfile = new BackupFile($this->argument('filename'), $database, $this->getDumpsPath()); $this->filePath = $dbfile->path(); $this->fileName = $dbfile->name(); $status = $database->dump($this->filePath); $handler = new BackupHandler($this->colors); // Error //---------------- if ($status !== true) { return $this->line($handler->errorResponse($status)); } // Compression //---------------- if ($this->isCompressionEnabled()) { $this->compress(); $this->fileName .= ".gz"; $this->filePath .= ".gz"; } $this->line($handler->dumpResponse($this->argument('filename'), $this->filePath, $this->fileName)); // S3 Upload //---------------- if ($this->option('upload-s3')) { $this->uploadS3(); $this->line($handler->s3DumpResponse()); if ($this->option('keep-only-s3')) { File::delete($this->filePath); $this->line($handler->localDumpRemovedResponse()); } } }
public static function boot() { parent::boot(); Event::deleting(function ($event) { File::delete($event->image); File::delete($event->thumbnail); }); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $image = image::findOrFail($id); $files = [public_path() . "/images/products/" . $image->image, public_path() . "/images/products/med_" . $image->image, public_path() . "/images/products/tmb_" . $image->image]; File::delete($files); image::destroy($image->id); return redirect()->back(); }