コード例 #1
0
 public function multipleUpload(Request $request)
 {
     // getting all of the post data
     $files = $request->file('images');
     $title = $request->input('title');
     $caption = $request->input('caption');
     if (sizeof($request->input('type')) > 0) {
         $types = $_POST['type'];
     }
     // Making counting of uploaded images
     $file_count = count($files);
     // start count how many uploaded
     $uploadcount = 0;
     foreach ($files as $file) {
         $rules = array('file' => 'required|mimes:png,gif,jpeg,jpg', 'title' => 'required|max:255', 'caption' => 'max:1000');
         $validator = Validator::make(array('file' => $file, 'title' => $title, 'caption' => $caption), $rules);
         if ($validator->passes()) {
             $size = $file->getSize();
             $destinationPath = './images/Amazing Lock Screen/';
             //upload path
             $extension = $file->getClientOriginalExtension();
             // get image extension
             $filename = time() . $file->getClientOriginalName() . '.' . $extension;
             //filename
             $file->move($destinationPath, $filename);
             // move
             $uploadcount++;
             $image = new Image();
             $image->title = $title;
             $image->caption = $caption;
             $image->url_path = $filename;
             $image->vote_count = 0;
             $image->user_id = Auth::user()->id;
             $image->size = $size;
             $image->save();
             if (sizeof($request->input('type')) > 0) {
                 foreach ($types as $type) {
                     $photoTag = new PhotoTag();
                     $photoTag->image_id = $image->id;
                     $photoTag->tag_id = $type;
                     $photoTag->save();
                 }
             }
         }
     }
     if ($uploadcount == $file_count) {
         Session::flash('success', 'Upload successfully');
         return Redirect::to('myphotos');
     } else {
         return Redirect::to('myphotos')->withInput()->withErrors($validator);
     }
 }