Пример #1
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 handleUpload(Request $request)
 {
     $this->checkUpload($request);
     $t = new Texture();
     $t->name = $request->input('name');
     $t->type = $request->input('type');
     $t->likes = 1;
     $t->hash = Utils::upload($_FILES['file']);
     $t->size = ceil($_FILES['file']['size'] / 1024);
     $t->public = $request->input('public') == 'true' ? "1" : "0";
     $t->uploader = $this->user->uid;
     $t->upload_at = Utils::getTimeFormatted();
     $cost = $t->size * ($t->public == "1" ? Option::get('score_per_storage') : Option::get('private_score_per_storage'));
     if ($this->user->getScore() < $cost) {
         return json(trans('skinlib.upload.lack-score'), 7);
     }
     $results = Texture::where('hash', $t->hash)->get();
     if (!$results->isEmpty()) {
         foreach ($results as $result) {
             // if the texture already uploaded was setted to private,
             // then allow to re-upload it.
             if ($result->type == $t->type && $result->public == "1") {
                 return json(trans('skinlib.upload.repeated'), 0, ['tid' => $result->tid]);
             }
         }
     }
     $t->save();
     $this->user->setScore($cost, 'minus');
     if ($this->user->getCloset()->add($t->tid, $t->name)) {
         return json(trans('skinlib.upload.success', ['name' => $request->input('name')]), 0, ['tid' => $t->tid]);
     }
 }