/**
  * @return string
  */
 public function getRename()
 {
     $old_name = Input::get('file');
     $new_name = Input::get('new_name');
     $file_path = parent::getPath('directory');
     $thumb_path = parent::getPath('thumb');
     $old_file = $file_path . $old_name;
     if (!File::isDirectory($old_file)) {
         $extension = File::extension($old_file);
         $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension;
     }
     $new_file = $file_path . $new_name;
     if (File::exists($new_file)) {
         return Lang::get('laravel-filemanager::lfm.error-rename');
     }
     if (File::isDirectory($old_file)) {
         File::move($old_file, $new_file);
         return 'OK';
     }
     File::move($old_file, $new_file);
     if ('Images' === $this->file_type) {
         File::move($thumb_path . $old_name, $thumb_path . $new_name);
     }
     return 'OK';
 }
 /**
  * @return string
  */
 public function getRename()
 {
     $old_name = Input::get('file');
     $new_name = trim(Input::get('new_name'));
     $file_path = parent::getPath('directory');
     $thumb_path = parent::getPath('thumb');
     $old_file = $file_path . $old_name;
     if (!File::isDirectory($old_file)) {
         $extension = File::extension($old_file);
         $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension;
     }
     $new_file = $file_path . $new_name;
     if (Config::get('lfm.alphanumeric_directory') && preg_match('/[^\\w-]/i', $new_name)) {
         return Lang::get('laravel-filemanager::lfm.error-folder-alnum');
     } elseif (File::exists($new_file)) {
         return Lang::get('laravel-filemanager::lfm.error-rename');
     }
     if (File::isDirectory($old_file)) {
         File::move($old_file, $new_file);
         Event::fire(new FolderWasRenamed($old_file, $new_file));
         return 'OK';
     }
     File::move($old_file, $new_file);
     if ('Images' === $this->file_type) {
         File::move($thumb_path . $old_name, $thumb_path . $new_name);
     }
     Event::fire(new ImageWasRenamed($old_file, $new_file));
     return 'OK';
 }
Exemplo n.º 3
0
 private function checkSharedFolderExists()
 {
     $path = $this->getPath('share');
     if (!File::exists($path)) {
         File::makeDirectory($path, $mode = 0777, true, true);
     }
 }
Exemplo n.º 4
0
 /**
  * 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('');
     }
 }
Exemplo n.º 5
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // Check file exists
     if (!File::exists($this->argument('file'))) {
         $this->comment('No coverage file found, skipping.');
         return 0;
     }
     // Open serialised file
     $serialised = File::get($this->argument('file'));
     if (!Str::startsWith($serialised, '<?php')) {
         $coverage = unserialize($serialised);
         // Require PHP object in file
     } else {
         $coverage = (require $this->argument('file'));
     }
     // Check coverage percentage
     $total = $coverage->getReport()->getNumExecutableLines();
     $executed = $coverage->getReport()->getNumExecutedLines();
     $percentage = nf($executed / $total * 100, 2);
     // Compare percentage to threshold
     $threshold = $this->argument('threshold');
     if ($percentage >= $threshold) {
         $this->info("Code Coverage of {$percentage}% is higher than the minimum threshold required {$threshold}%!");
         return;
     }
     // Throw error
     $this->error("Code Coverage of {$percentage}% is below than the minimum threshold required {$threshold}%!");
     return 1;
 }
 /**
  * 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' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
         }
     }
 }
Exemplo n.º 7
0
 /**
  * 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 function upload()
 {
     if (Session::get('isLogged') == true) {
         return \Plupload::file('file', function ($file) {
             // екстракт на наставката
             $originName = $file->getClientOriginalName();
             $array = explode('.', $originName);
             $extension = end($array);
             // името без наставка
             $name = self::normalizeString(pathinfo($originName, PATHINFO_FILENAME));
             // base64 од името на фајлот
             $fileName = base64_encode($name) . '.' . $extension;
             // пат до фајлот
             $path = storage_path() . '\\upload\\' . Session::get('index') . '\\' . $fileName;
             if (!File::exists($path)) {
                 // фајловите се чуваат во storage/upload/brIndeks/base64(filename).extension
                 $file->move(storage_path('upload/' . Session::get('index')), $fileName);
                 return ['success' => true, 'message' => 'Upload successful.', 'deleteUrl' => action('FileController@delete', [$file])];
             } else {
                 return ['success' => false, 'message' => 'File with that name already exists!', 'deleteUrl' => action('FileController@delete', [$file])];
             }
         });
     } else {
         abort(404);
     }
 }
 /**
  * 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' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
         }
     }
 }
Exemplo n.º 10
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $rules = ['name' => ['required', 'unique:archive,name', 'regex:' . config('app.expressions.dir')]];
     if ($this->systemAdmin) {
         $rules['department_id'] = 'required';
     }
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     DB::transaction(function () use($request) {
         #add all papers from department to archive
         $archive = Archive::create($request->all());
         $department = Department::findOrFail($request->get('department_id'));
         $paperObj = new PaperClass();
         $archivePath = 'archive/';
         if (!File::exists($archivePath . $archive->name)) {
             File::makeDirectory($archivePath . $archive->name);
         }
         $newPath = $archivePath . $archive->name . '/';
         $oldPath = $paperObj->prefix() . '/' . $department->keyword . '/';
         foreach ($department->papers()->archived()->get() as $paper) {
             $paper->archive()->associate($archive);
             $paper->save();
             File::move($oldPath . $paper->source, $newPath . $paper->source);
             if ($paper->payment_source) {
                 File::move($oldPath . $paper->payment_source, $newPath . $paper->payment_source);
             }
         }
     });
     return redirect()->action('Admin\\ArchiveController@index')->with('success', 'updated');
 }
 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'));
 }
Exemplo n.º 12
0
 public static function getImageUrl($filename, $size = '', $default = '')
 {
     if (filter_var($filename, FILTER_VALIDATE_URL)) {
         return $filename;
     }
     $image = '';
     if ($filename != '' && strlen($filename) !== 0) {
         if ($size !== '') {
             if (File::exists(public_path('images/uploads' . self::getImage($filename, $size)))) {
                 $image = asset('images/uploads' . self::getImage($filename, $size));
             } else {
                 if (File::exists(public_path('images/uploads' . $filename))) {
                     $image = asset('images/uploads' . $filename);
                 } else {
                     $image = asset('images/uploads' . self::getImage($default, $size));
                 }
             }
         } else {
             if (File::exists(public_path('/images/uploads' . $filename))) {
                 $image = asset('images/uploads' . $filename);
             } else {
                 $image = asset('images/uploads' . self::getImage($default, $size));
             }
         }
     } else {
         $image = asset('images/uploads' . self::getImage($default, $size));
     }
     return $image;
 }
Exemplo n.º 13
0
 protected function imageAvatar()
 {
     $path = 'upload/' . date('Ym/d/');
     $filename = KRandom::getRandStr() . '.jpg';
     if (!File::exists(public_path($path))) {
         File::makeDirectory(public_path($path), 493, true);
     }
     while (File::exists(public_path($path) . $filename)) {
         $filename = KRandom::getRandStr() . '.jpg';
     }
     $this->image->resize(new \Imagine\Image\Box(300, 300))->save(public_path($path) . $filename);
     ImageModel::createUploadedImage($path . $filename, URL::asset($path . $filename));
     $user = AuthModel::user();
     $url = URL::asset($path . $filename);
     if ($user) {
         if ($user->profile) {
             $user->profile->avatar = $url;
             $user->profile->save();
         } else {
             ProfileModel::create(array('user_id' => $user->id, 'avatar' => $url));
         }
     } else {
     }
     return $url;
 }
Exemplo n.º 14
0
 public function save(Request $request)
 {
     $rules = array('colour_code' => 'required', 'w_texture' => 'required|notcontains0');
     $messages = ['w_texture.required' => 'Je moet een texture image uploaden', 'colour_code.required' => 'Koppel een kleur aan deze texture', 'w_texture.notcontains0' => "Er was geen texture image crop selectie"];
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return redirect('/cms/texture/create')->withErrors($validator)->withInput();
     } else {
         $file = $request->file('slider_img');
         $fileUploadDir = 'files/uploads/';
         $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
         if (File::exists($fileUploadDir . $fileName)) {
             $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
         }
         $this->dispatch(new ProcessTextures($fileName));
         if ($fileName) {
             $texture = new Texture();
             $texture->title = $request->get("slider_title");
             $texture->img = $fileName;
             $texture->colour_id = $request->get("colour_code");
             $texture->save();
         }
         return redirect('/cms/texture');
     }
 }
 public function getAlbumsList()
 {
     $directoryPath = $this->getAlbumsFolderLocation();
     $albums_list = array();
     $list = null;
     if (File::exists($directoryPath)) {
         $list = File::directories($directoryPath);
     }
     if ($list != null) {
         foreach ($list as $album) {
             $locationExplode = explode("/", $album);
             $folderName = end($locationExplode);
             if (!StringUtils::getInstance()->startsWith($folderName, "hidden_")) {
                 if ($this->isAlbumList($album)) {
                     $titleFilePath = $album . DIRECTORY_SEPARATOR . "title.txt";
                     if (File::exists($titleFilePath)) {
                         array_push($albums_list, $album);
                     }
                 } else {
                     array_push($albums_list, $album);
                 }
             }
         }
     }
     return $albums_list;
 }
 public function __construct()
 {
     //$this->beforeFilter(function(){  });
     $this->uriSegment = null;
     $this->modelName = null;
     $this->viewsPath = null;
     $this->resourceId = null;
     if (Route::input('alias') !== null) {
         $this->uriSegment = Route::input('alias');
         $this->viewsPath = File::exists(app_path('views/' . Config::get('reactiveadmin::uri') . '/' . $this->uriSegment)) ? Config::get('reactiveadmin::uri') . '.' . $this->uriSegment : 'reactiveadmin::default';
         $this->modelName = studly_case(str_singular(Route::input('alias')));
         $this->modelWrapper = App::make('model_wrapper');
         $this->modelWrapper->model($this->modelName);
         if (Route::input('id') !== null) {
             $this->resourceId = Route::input('id');
         }
         View::share('config', $this->modelWrapper->getConfig());
         // TODO: refactor this!
         // custom behavior
         switch ($this->uriSegment) {
             case 'settings':
                 View::composer(array('admin.' . $this->viewsPath . '.index'), function ($view) {
                     $view->with('settings', Settings::all());
                 });
                 break;
             default:
                 # code...
                 break;
         }
     }
     View::share('view', $this->uriSegment);
     View::share('model', $this->modelName);
 }
Exemplo n.º 17
0
 /**
  * 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;
 }
Exemplo n.º 18
0
 /**
  * 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.');
 }
Exemplo n.º 20
0
 /**
  * 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 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'));
 }
Exemplo n.º 22
0
 /**
  * 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' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
         }
     }
 }
Exemplo n.º 23
0
 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;
 }
Exemplo n.º 24
0
 public function rmFile($filename)
 {
     $fileUploadDir = 'files/uploads/';
     if (File::exists($fileUploadDir . $filename)) {
         File::delete($fileUploadDir . $filename);
     }
 }
Exemplo n.º 25
0
 public function buildFileName($invoice = false)
 {
     $key = $invoice ? 'invoice' : 'paper';
     if ($this->files[$key . '_name']) {
         #if already build
         return $this->files[$key . '_name'];
     }
     if (!request()->file($this->files[$key])) {
         return '';
     }
     $ext = request()->file($this->files[$key])->getClientOriginalExtension();
     $name = request()->file($this->files[$key])->getClientOriginalName();
     $name = str_replace('.' . $ext, '', $name);
     #check if name is bigger then 90 chars and cut + remove ... from string
     $name = str_limit($name, 90);
     if (substr($name, -1) == '.') {
         $name = substr($name, 0, -3);
     }
     $userName = explode(' ', auth()->user()->name);
     $name .= '_' . $userName[0][0] . $userName[1][0];
     #get user letters
     if ($invoice) {
         $name .= 'I';
         #add i before number
     }
     $name .= rand(1, 999);
     $name .= '.' . $ext;
     #add extension
     if (File::exists(self::$path . $name)) {
         $name = $this->buildFileName($invoice);
     }
     $this->files[$key . '_name'] = $name;
     return $name;
 }
Exemplo n.º 26
0
 private function checkSharedFolderExists()
 {
     $path = base_path($this->file_location . Config::get('lfm.shared_folder_name'));
     if (!File::exists($path)) {
         File::makeDirectory($path, $mode = 0777, true, true);
     }
 }
Exemplo n.º 27
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     try {
         $sourceDir = __DIR__ . "/../testing";
         $destinationDir = "config/testing";
         $testcase_main = "tests/TestCase.php";
         if (File::exists($testcase_main)) {
             $get_contents = __DIR__ . "/../BaseTestcase/Testcase.php";
             if (File::exists($get_contents)) {
                 $success = File::copyDirectory($sourceDir, $destinationDir);
                 file_put_contents($testcase_main, file_get_contents($get_contents));
                 if ($success) {
                     $this->info("Testing directory for local database( Temporary Storage ) is successfully created");
                 } else {
                     $this->error("There was an error in creating local testing folder");
                 }
             } else {
                 $this->error("No file in package directory");
             }
         } else {
             $this->error("No file in tests directory");
         }
     } catch (\Exception $e) {
         die("The base file doesn't exist");
     }
 }
Exemplo n.º 28
0
 /**
  * Checks if file exsits
  * @param  string $file filename without .md
  * @return data         The file himself
  */
 public function fileExists($file)
 {
     if (!File::exists($this->location . '/' . $file . '.md')) {
         return 'File does not exists';
     }
     return File::get($this->location . '/' . $file . '.md');
 }
Exemplo n.º 29
0
 public function saveThumbnailImage(Request $request)
 {
     $file = $request->file('product_thumbnail_img');
     if ($file && $_FILES["product_thumbnail_img"]["tmp_name"]) {
         try {
             $preview_img_x = $_POST['x_thumbnail'];
             $preview_img_y = $_POST['y_thumbnail'];
             $preview_img_w = $_POST['w_thumbnail'];
             $preview_img_h = $_POST['h_thumbnail'];
             $display_w = $_POST['display_w_thumbnail'];
             $file_path = $file->getPathname();
             $orig_w = getimagesize($_FILES["product_thumbnail_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) ($preview_img_w * $ratio), (int) ($preview_img_h * $ratio), (int) ($preview_img_x * $ratio), (int) ($preview_img_y * $ratio));
             $img->resize(300, 167);
             $img->save($fileUploadDir . $fileName);
             return $fileName;
         } catch (Exception $e) {
             return false;
         }
     }
     return false;
 }
Exemplo n.º 30
0
 protected function setupLangDir()
 {
     $langDir = realpath(app_path() . '/../resources/lang');
     if (File::exists("{$langDir}/en")) {
         File::move("{$langDir}/en", "{$langDir}/en_GB");
     }
 }