/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), Post::$rules);
     if ($validator->fails()) {
         Session::flash('errorMessage', 'Something went wrong here!');
         return Redirect::back()->withErrors($validator)->withInput();
     } else {
         $post = new Post();
         $post->title = Input::get('title');
         $post->body = Input::get('body');
         $post->user_id = Auth::id();
         if (Input::hasFile('picture')) {
             if (Input::file('picture')->isValid()) {
                 Storage::upload(Input::file('picture'), "{$post->picture}" . "jpg");
             }
             $post->picture = Input::file('picture');
         }
         if (Input::has('tags')) {
             $post->tags = implode(', ', Input::get('tags'));
         }
         $post->save();
         $posts = Post::paginate(5);
         Session::flash('goodMessage', 'All went right here!');
         return View::make('posts/index')->with('posts', $posts);
     }
 }
示例#2
0
文件: test.php 项目: xuyintao/thindev
    echo "文件不存在";
    // exit;
} else {
    $file = $_FILES["Filedata"];
    if (MAX_FILE_SIZE < $file["size"]) {
        echo "文件已超过限制!";
        exit;
    }
    /*if(!in_array($file["type"], $uptypes))
    //检查文件类型
    {
    echo "文件不是图片格式";
    exit;
    }*/
    $filename = $file["tmp_name"];
    $pinfo = pathinfo($file["name"]);
    $ftype = $pinfo[extension];
    $filenamenew = uniqid(date("Ymd"), true) . "." . $ftype;
    $destination = $destination_folder . $filenamenew;
    //存储
    $stor = new Storage();
    $picurl = $stor->upload(FILE_DIR_TEMP, $destination, $filename);
}
/*echo "dddd";
$mmcache=new MMCache();
$mmcache->getValue("key");

$demo=new Demo();
echo 'aaa';
$demo=new Demo();*/
//return;
示例#3
0
 /**
  * 上传文件的主处理方法
  * @param $base64
  * @return mixed
  */
 private function upFile($base64)
 {
     //处理base64上传
     if ($base64) {
         $content = $_POST[$this->fileField];
         $this->base64ToImage($content);
         return;
     }
     //处理普通上传
     $file = $this->file = $_FILES[$this->fileField];
     if (!$file) {
         $this->stateInfo = $this->getStateInfo('POST');
         return;
     }
     if ($this->file['error']) {
         $this->stateInfo = $this->getStateInfo($file['error']);
         return;
     }
     if (!is_uploaded_file($file['tmp_name'])) {
         $this->stateInfo = $this->getStateInfo("UNKNOWN");
         return;
     }
     $this->oriName = $file['name'];
     $this->fileSize = $file['size'];
     $this->fileType = $this->getFileExt();
     if (!$this->checkSize()) {
         $this->stateInfo = $this->getStateInfo("SIZE");
         return;
     }
     if (!$this->checkType()) {
         $this->stateInfo = $this->getStateInfo("TYPE");
         return;
     }
     $this->fullName = $this->getFolder() . '/' . $this->getName();
     if ($this->stateInfo == $this->stateMap[0]) {
         if (!Storage::upload($file["tmp_name"], $this->fullName)) {
             $this->stateInfo = $this->getStateInfo("MOVE");
         } else {
             $this->url = Storage::getUrl($this->fullName);
         }
     }
 }
示例#4
0
 /**
  * 通过Storage实现文件保存
  *
  */
 protected function save_to_storage()
 {
     $storage = new Storage($this->config['storage_config']);
     return $storage->upload($this->file['temp'], $this->filename);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // create the validator
     $validator = Validator::make(Input::all(), Article::$rules);
     // attempt validation
     if ($validator->fails()) {
         return Redirect::back()->withInput()->withErrors($validator);
     } else {
         $article = Article::find($id);
         $article->title = Input::get('title');
         $article->content = Input::get('content');
         // check for img upload
         if (Input::hasFile('photo')) {
             if ($validFile = Input::file('photo')->isValid()) {
                 // delete the old image allowing reuse of file name
                 Storage::delete("{$article->id}-photo");
                 Storage::upload(Input::file('photo'), "{$article->id}-photo");
             } else {
                 return Redirect::back()->withInput()->withErrors($validFile);
             }
         }
         if ($article->save()) {
             Session::flash('successMessage', "Wolfpack Updated: {$article->title}");
             Log::info("Updated article with id: {$id}");
             return Redirect::action('ArticlesController@index');
         } else {
             Session::flash('errorMessage', 'Plz no try to break things.');
             Log::error("Unable to update article with the id: {$id}");
             return Redirect::action('ArticlesController@edit', $id)->withInput()->withErrors($validator);
         }
     }
 }