예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validation = Validator::make($input = Input::all(), Blink::$rules);
     if ($validation->passes()) {
         $imgFld = Blink::GenerateFolder();
         $mime = Input::file('item')->getMimeType();
         $extension = Input::file('item')->getClientOriginalExtension();
         $fileType = FileType::whereRaw("LOWER(mimetype)='" . strtolower($mime) . "'")->firstOrFail();
         $input["file_type_id"] = $fileType->id;
         $tempF = tempnam($imgFld, '');
         $tempF = str_replace(".tmp", "", basename($tempF));
         Input::file('item')->move($imgFld, $tempF . "." . $extension);
         $input["file_location"] = $imgFld . $tempF . "." . $extension;
         $input["upload_ip"] = Request::getClientIp();
         $c = 0;
         $token = Blink::getToken(10);
         $uniqueC = Blink::where("url_token", "=", $token)->whereNull("expired_at")->count();
         while ($uniqueC > 0 && $c < 20) {
             $c++;
             $token = Blink::getToken(10);
             $uniqueC = Blink::where("url_token", "=", $token)->whereNull("expired_at")->whereNull("deleted_at")->count();
         }
         $input["url_token"] = $token;
         $blink = Blink::create($input);
         $base = SysVariable::Get(SysVariable::$shorten_url);
         echo $base . $blink->url_token;
         //return Redirect::route('blinks.index');
     }
     /*return Redirect::route('blinks.create')
     		->withInput()
     		->withErrors($validation)
     		->with('message', 'There were validation errors.');*/
 }