Ejemplo n.º 1
1
 public function post_new()
 {
     $input = Input::all();
     //grab our input
     $rules = array('name' => 'required|alpha', 'lastName' => 'required|alpha', 'permit' => 'required|min:2', 'lot' => 'required|integer', 'msc' => 'integer', 'ticket' => 'required|min:2|numeric|unique:tickets,ticketID', 'fineAmt' => 'required|numeric', 'licensePlate' => 'required|alpha_num', 'licensePlateState' => 'required|max:2', 'dateIssued' => 'required', 'violations' => 'required', 'areaOfViolation' => 'required|alpha_num', 'appealLetter' => 'required|max:700');
     //validation rules
     $validation = Validator::make($input, $rules);
     //let's run the validator
     if ($validation->fails()) {
         return Redirect::to('appeal/new')->with_errors($validation);
     }
     //hashing the name of the file uploaded for security sake
     //then we'll be dropping it into the public/uploads file
     //get the file extension
     $extension = File::extension($input['appealLetter']['name']);
     //encrypt the file name
     $file = Crypter::encrypt($input['appealLetter']['name'] . time());
     //for when the crypter likes to put slashes in our scrambled filname
     $file = preg_replace('#/+#', '', $file);
     //concatenate extension and filename
     $filename = $file . "." . $extension;
     Input::upload('appealLetter', path('public') . 'uploads/', $filename);
     //format the fine amount in case someone screws it up
     $fineamt = number_format(Input::get('fineAmt'), 2, '.', '');
     //inserts the form data into the database assuming we pass validation
     Appeal::create(array('name' => Input::get('name'), 'lastName' => Input::get('lastName'), 'permitNumber' => Input::get('permit'), 'assignedLot' => Input::get('lot'), 'MSC' => Input::get('msc'), 'ticketID' => Input::get('ticket'), 'fineAmt' => $fineamt, 'licensePlate' => Str::upper(Input::get('licensePlate')), 'licensePlateState' => Input::get('licensePlateState'), 'dateIssued' => date('Y-m-d', strtotime(Input::get('dateIssued'))), 'violations' => Input::get('violations'), 'areaOfViolation' => Input::get('areaOfViolation'), 'letterlocation' => URL::to('uploads/' . $filename), 'CWID' => Session::get('cwid')));
     return Redirect::to('appeal/')->with('alertMessage', 'Appeal submitted successfully.');
 }
Ejemplo n.º 2
0
 public function post_upload()
 {
     $input = Input::get();
     $file = Input::file('fileInput');
     $separator = $input['claimdetailid'] != NULL ? $input['claimid'] . '/' . $input['claimdetailid'] : $input['claimid'];
     $extension = File::extension($file['name']);
     $directory = 'upload/claims/' . sha1(Auth::user()->userid) . '/' . str_replace("-", "", date('Y-m-d')) . '/' . $separator;
     $filename = Str::random(16, 'alpha') . time() . ".{$extension}";
     if (!is_dir(path('public') . $directory)) {
         mkdir(path('public') . $directory, 0777, true);
     }
     $maxSize = ini_get('upload_max_filesize') * 1024 * 1024 * 1024;
     if ($file['size'] != null && $file['size'] < $maxSize) {
         try {
             $upload_success = Input::upload('fileInput', path('public') . $directory, $filename);
             if ($upload_success) {
                 $input['recpath'] = $directory . '/' . $filename;
                 $receipt = new Claims_Receipt();
                 $receipt->fill($input);
                 $receipt->save();
                 Log::write('Claims Receipt', 'File Uploaded : ' . $filename . ' by ' . Auth::user()->username);
                 return $directory . '/' . $filename;
             }
         } catch (Exception $e) {
             Log::write('Claims Receipt', 'Upload error: ' . $e->getMessage());
         }
     } else {
         Log::write('Claims Receipt', 'Upload error: Exceed max size ' . ini_get('upload_max_filesize'));
     }
 }
 /**
  * Attempts to upload a file, adds it to the database and removes other database entries for that file type if they are asked to be removed
  * @param  string  $field             The name of the $_FILES field you want to upload
  * @param  boolean $upload_type       The type of upload ('news', 'gallery', 'section') etc
  * @param  boolean $type_id           The ID of the item (above) that the upload is linked to
  * @param  boolean $remove_existing   Setting this to true will remove all existing uploads of the passed in type (useful for replacing news article images when a new one is uploaded for example)
  * @return object                     Returns the upload object so we can work with the uploaded file and details
  */
 public static function upload($field = 'image', $upload_type = false, $type_id = false, $remove_existing = false)
 {
     if (!$field || !$upload_type || !$type_id) {
         return false;
     }
     $input = Input::file($field);
     if ($input && $input['error'] == UPLOAD_ERR_OK) {
         if ($remove_existing) {
             static::remove($upload_type, $type_id);
         }
         $ext = File::extension($input['name']);
         $filename = Str::slug(Input::get('title'), '-');
         Input::upload('image', './uploads/' . $filename . '.' . $ext);
         $upload = new Upload();
         $upload->link_type = $upload_type;
         $upload->link_id = $type_id;
         $upload->filename = $filename . '.' . $ext;
         if (Koki::is_image('./uploads/' . $filename . '.' . $ext)) {
             $upload->small_filename = $filename . '_small' . '.' . $ext;
             $upload->thumb_filename = $filename . '_thumb' . '.' . $ext;
             $upload->image = 1;
         }
         $upload->extension = $ext;
         $upload->user_id = Auth::user()->id;
         $upload->save();
         return $upload;
     }
 }
Ejemplo n.º 4
0
 public function action_create()
 {
     /*$slug = $this->slugger(Input::get('title'));
     
     		$db = Post::create(array(
     				'post_title' => Input::get('title'),
     				'post_content' => Input::get('content'),
     				'excerpt' => Input::get('excerpt'),
     				'slug' => $slug,
     				'user_id' => Auth::user()->id,
     			));
     		
     		if(!$db){
     			Log::write('posts.create', 'Post was not created, post->create() returned false.');
     			 return Redirect::to('posts/new')
     		                 ->with('error_create', 'Unable to create post!');
     		} */
     $db = Post::find(2);
     $input = Input::all();
     $rules = array('image' => 'required|image|max:200');
     $messages = array('image_required' => 'Please select an image for upload!', 'image_max' => 'Make sure image is no larger than 500kb', 'image_image' => 'Please select an image file');
     $validation = Validator::make($input, $rules, $messages);
     if ($validation->fails()) {
         return Redirect::to('posts/new')->with_errors($validation);
     }
     $extension = File::extension($input['image']['name']);
     $directory = path('public') . 'uploads/' . sha1(Auth::user()->id);
     $filename = sha1(Auth::user()->id . time()) . ".{$extension}";
     $upload_success = Input::upload('image', $directory, $filename);
     if ($upload_success) {
         $photo = new Image(array('image_name' => $filename, 'image_location' => '/uploads/' . sha1(Auth::user()->id) . '/' . $filename, 'image_size' => $input['image']['size'], 'image_type' => $extension));
         $db->images()->insert($photo);
     }
     return Redirect::to('posts/new')->with('status_create', 'New Post Created')->with('id', $db->id);
 }
Ejemplo n.º 5
0
 public function action_create()
 {
     $input = Input::all();
     if (isset($input['description'])) {
         $input['description'] = filter_var($input['description'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     }
     $rules = array('image' => 'required|image|max:200', 'description' => 'required', 'name' => 'required');
     $messages = array('image_required' => 'Please select an image for upload!', 'image_max' => 'Make sure image is no larger than 500kb', 'image_image' => 'Please select an image file');
     $validation = Validator::make($input, $rules, $messages);
     if ($validation->fails()) {
         return Redirect::to('admin/gallery/new')->with_errors($validation);
     }
     $extension = File::extension($input['image']['name']);
     $directory = path('public') . 'uploads/' . sha1(Auth::user()->id);
     $filename = sha1(Auth::user()->id . time()) . ".{$extension}";
     $upload_success = Input::upload('image', $directory, $filename);
     if ($upload_success) {
         $photo = new Image(array('name' => Input::get('name'), 'location' => '/uploads/' . sha1(Auth::user()->id) . '/' . $filename, 'description' => $input['description'], 'type' => $extension));
         Auth::user()->images()->insert($photo);
         Session::flash('status_create', 'Successfully uploaded your new Instapic');
         Session::flash('id', $photo->id);
     } else {
         Log::write('admin.gallery.create', 'Image was not uploaded, $photo->create() returned false.');
         Session::flash('error_create', 'An error occurred while uploading your new Instapic - please try again.');
     }
     return Redirect::to('admin/gallery/new');
 }
Ejemplo n.º 6
0
 public static function upload($model, $modelName, $name, $attribute, $removePastImage = true, $sizes = array())
 {
     $uploadOptions = $attribute["uploadOptions"];
     $path = "public";
     $beforeImage = $model->{$name};
     if (isset($uploadOptions["sizes"])) {
         $sizes = $uploadOptions["sizes"];
     }
     if (isset($uploadOptions["path"])) {
         $path = $uploadOptions["path"];
     }
     $files = Input::file($name);
     if ($files["name"] == "") {
         return false;
     }
     $extension = File::extension($files["name"]);
     $directory = path($path) . $uploadOptions["directory"];
     $nameFile = sha1(Session::has("token_user") . microtime());
     $filename = "{$nameFile}.{$extension}";
     $fullPath = $directory . "/" . $filename;
     $defaultImage = $directory . "/" . $filename;
     $defaultImageName = $filename;
     $successUpload = Input::upload($name, $directory, $filename);
     if ($successUpload === false) {
         return false;
     }
     if (File::exists($directory . "/" . $beforeImage)) {
         File::delete($directory . "/" . $beforeImage);
     }
     var_dump($beforeImage);
     $beforeExtension = File::extension($beforeImage);
     $preg = $directory . "/" . preg_replace("/\\.{$beforeExtension}/", "", $beforeImage);
     if (!empty($beforeImage)) {
         foreach (glob("{$preg}*", GLOB_ONLYDIR) as $key => $dir) {
             File::rmdir($dir);
         }
     }
     foreach ($sizes as $key => $size) {
         if (!preg_match("/\\d*x\\d*/", $size)) {
             throw new Exception("Size doesnt have a valid format valid for {$size} example: ddxdd", 1);
         }
         if (!class_exists("Resizer")) {
             throw new Exception("Bundle Resizer must be installed <br> Please got to <a href='http://bundles.laravel.com/bundle/resizer'>http://bundles.laravel.com/bundle/resizer</a>", 1);
         }
         $filename = $nameFile . "_{$key}.{$extension}";
         $sizeOptions = preg_split("/x/", $size);
         $fullPath = $directory . "/{$nameFile}{$key}/" . $filename;
         $beforeImageWithSize = $directory . "/{$nameFile}{$key}/" . $beforeImage;
         if (!is_dir($directory . "/" . $nameFile . $key)) {
             mkdir($directory . "/" . $nameFile . $key, 0777);
         }
         $success = Resizer::open($defaultImage)->resize($sizeOptions[0], $sizeOptions[1], 'fit')->save($fullPath, 90);
         if ($success === false) {
             return false;
         }
     }
     return array("fullPath" => $defaultImage, "fileName" => $defaultImageName);
 }
Ejemplo n.º 7
0
 public function post_results()
 {
     $rules = array('sample' => 'required|image');
     //Validate input
     $validation = Validator::make(Input::all(), $rules);
     if ($validation->fails()) {
         return Redirect::back()->with_errors($validation)->with_input();
     }
     $url = array();
     //save files if exists
     foreach (array('sample', 'control') as $image) {
         if (File::exists(Input::file($image . '.tmp_name'))) {
             $name = Input::file($image . '.name');
             $ext = strtolower(File::extension($name));
             $url[$image] = $this->upload_path . '/' . $image . "." . $ext;
             $url[$image] = $this->image_url . '/' . $image . "." . $ext;
             Input::upload($image, $this->upload_path, $image . "." . $ext);
         }
     }
     //end foreach
     //analyze images submitted
     $litmus = new Litmus($this->LITMUS_ACCOUNT, $this->LITMUS_TOKEN);
     if (isset($url['sample'])) {
         $litmus->set_sample_url($url['sample']);
     }
     if (isset($url['control'])) {
         $litmus->set_control_url($url['control']);
     }
     if (Input::has('scale_id')) {
         $litmus->set_scale_id(Input::get('scale_id'));
     }
     $response = $litmus->analyze();
     if ($response->status == 'error') {
         echo $response->message;
         exit;
     }
     //recursive function for outputting a heirarchial data tree
     $string = "<ul>" . Mockup\Util::recursiveTree($response) . "</ul>";
     $data = array();
     $data['title'] = "Image Analysis";
     $data['lead'] = "Response from Litmus API";
     $tabs = array(array('Swatch', '#swatch', 'active'), array('Code', '#code'));
     $data['tabs'] = View::make('mockup::partials.tabs')->with('tabs', $tabs)->render();
     $data['code'] = $string;
     $data['response'] = $response;
     Asset::container('scripts')->add('colorbox', 'bundles/mockup/assets/js/colorbox.js');
     return View::make('mockup::pages.result', $data);
 }
Ejemplo n.º 8
0
 /**
  * Attempts to upload a file, adds it to the database and removes other database entries for that file type if they are asked to be removed
  * @param  string  $field             The name of the $_FILES field you want to upload
  * @param  boolean $upload_type       The type of upload ('news', 'gallery', 'section') etc
  * @param  boolean $type_id           The ID of the item (above) that the upload is linked to
  * @param  boolean $remove_existing   Setting this to true will remove all existing uploads of the passed in type (useful for replacing news article images when a new on
  * @param  boolean $title             Sets the title of the upload
  * @param  boolean $path_to_store     Sets the path to the upload (where it should go)
  * @return object                     Returns the upload object so we can work with the uploaded file and details
  */
 public static function upload($details = array())
 {
     $upload_details = array('remove_existing_for_link' => true, 'path_to_store' => path('public') . 'uploads/', 'resizing' => array('small' => array('w' => 200, 'h' => 200), 'thumb' => array('w' => 200, 'h' => 200)));
     if (!empty($details)) {
         $required_keys = array('upload_field_name', 'upload_type', 'upload_link_id', 'title');
         $continue = true;
         foreach ($required_keys as $key) {
             if (!isset($details[$key]) || empty($details[$key])) {
                 Messages::add('error', 'Your upload array details are not complete... please fill this in properly.');
                 $continue = false;
             }
         }
         if ($continue) {
             $configuration = $details + $upload_details;
             $input = Input::file($configuration['upload_field_name']);
             if ($input && $input['error'] == UPLOAD_ERR_OK) {
                 if ($configuration['remove_existing_for_link']) {
                     static::remove($configuration['upload_type'], $configuration['upload_link_id']);
                 }
                 $ext = File::extension($input['name']);
                 $filename = Str::slug($configuration['upload_type'] . '-' . $configuration['upload_link_id'] . '-' . Str::limit(md5($input['name']), 10, false) . '-' . $configuration['title'], '-');
                 Input::upload($configuration['upload_field_name'], $configuration['path_to_store'], $filename . '.' . $ext);
                 $upload = new Upload();
                 $upload->link_type = $configuration['upload_type'];
                 $upload->link_id = $configuration['upload_link_id'];
                 $upload->filename = $filename . '.' . $ext;
                 if (Koki::is_image($configuration['path_to_store'] . $filename . '.' . $ext)) {
                     $upload->small_filename = $filename . '_small' . '.' . $ext;
                     $upload->thumb_filename = $filename . '_thumb' . '.' . $ext;
                     $upload->image = 1;
                 }
                 $upload->extension = $ext;
                 $upload->user_id = Auth::user()->id;
                 $upload->save();
                 if (Koki::is_image($configuration['path_to_store'] . $filename . '.' . $ext)) {
                     WideImage::load($configuration['path_to_store'] . $upload->filename)->resize($configuration['resizing']['small']['w'], $configuration['resizing']['small']['h'])->saveToFile($configuration['path_to_store'] . $upload->small_filename);
                     WideImage::load($configuration['path_to_store'] . $upload->small_filename)->crop('center', 'center', $configuration['resizing']['thumb']['w'], $configuration['resizing']['thumb']['h'])->saveToFile($configuration['path_to_store'] . $upload->thumb_filename);
                 }
                 return true;
             }
         }
     } else {
         Messages::add('error', 'Your upload array details are empty... please fill this in properly.');
     }
     return false;
 }
Ejemplo n.º 9
0
 public function post_upload()
 {
     $input = Input::all();
     $rules = array('file' => 'image|max:3000');
     $validation = Validator::make($input, $rules);
     if ($validation->fails()) {
         return Response::make($validation->errors->first(), 400);
     }
     $file = Input::file('file');
     $directory = path('public') . 'uploads/' . sha1(time());
     $filename = sha1(time() . time()) . ".jpg";
     $upload_success = Input::upload('file', $directory, $filename);
     if ($upload_success) {
         return Response::json('success', 200);
     } else {
         return Response::json('error', 400);
     }
 }
 public function postUpload()
 {
     $input = Input::all();
     $rules = array('photo' => 'required|image|max:500');
     $v = Validator::make($input, $rules);
     if ($v->fails()) {
         return Redirect::to('profile');
     }
     $extensions = File::extension($input['photo'], ['name']);
     $directory = path('app') . 'foundation-5.4.0/img' . sha1(Auth::user()->id);
     $filename = sha1(Auth::user()->id) . ".{$extension}";
     $upload_success = Input::upload('photo', $directory, $filename);
     if ($upload_success) {
         $photo = new Photo(array('location' => URL::to('uploads/' . sha1(Auth::user()->id) . '/' . $filename)));
         Auth::user()->photos()->insert($photo);
         Session::flash('status_success', 'successful yay');
     } else {
         Session::flash('status_error', 'failed NO!!!! upload failed');
     }
     return Redirect::to('profile');
 }
Ejemplo n.º 11
0
 public function post_create()
 {
     $file = null;
     $image_name = Opensim\UUID::random();
     $action = Input::get('action');
     if (isset($action) and $action == 'logo') {
         $file = Input::file('logo_image');
         $logo_path = path('public') . 'bundles/splashscreen/img/logo/';
         foreach (glob($logo_path . "logo.*") as $filename) {
             @File::delete($filename);
         }
         $path = $logo_path . $file['name'];
         $logo_parts = explode('.', $file['name']);
         $path = $logo_path;
         $image_name = 'logo.' . $logo_parts['1'];
         $image_path = '/bundles/splashscreen/img/logo/' . $image_name;
         Input::upload('logo_image', $path, $image_name);
         return View::make('splashscreen::backend.imagesbackgrounds.partials.logo', array('image_name' => $image_name, 'path' => $image_path))->render();
         Log::error($path);
     }
     if (isset($action) and $action == 'background') {
         $file = Input::file('background');
         $path = path('public') . 'bundles/splashscreen/img/backgrounds/';
         $ext = get_file_extension($file['name']);
         $image_name = $image_name . '.' . $ext;
         $image_path = '/bundles/splashscreen/img/backgrounds/' . $image_name;
         Input::upload('background', $path, $image_name);
         return View::make('splashscreen::backend.imagesbackgrounds.partials.image', array('image_name' => $image_name, 'path' => $image_path, 'action' => 'background'))->render();
     }
     if (isset($action) and $action == 'daytimebkg') {
         $file = Input::file('daytimebkg');
         $path = path('public') . 'bundles/splashscreen/img/day_time_bkgs/';
         $image_name = $file['name'];
         $image_path = '/bundles/splashscreen/img/day_time_bkgs/' . $image_name;
         Input::upload('daytimebkg', $path, $image_name);
         return View::make('splashscreen::backend.imagesbackgrounds.partials.day_time_bkgs', array('image_name' => $image_name, 'path' => $image_path, 'action' => 'daytimebkg'))->render();
     }
 }
Ejemplo n.º 12
0
 public function upload($field = 'image', $upload_type = false, $type_id = false)
 {
     if (!$field || !$upload_type || !$type_id) {
         return false;
     }
     if (Input::file($field)) {
         $input = Input::file('image');
         $ext = File::extension($input['name']);
         $filename = Str::slug(Input::get('title'), '-');
         Input::upload('image', './uploads/' . $filename . '.' . $ext);
         $upload = new Upload();
         $upload->link_type = $upload_type;
         $upload->link_id = $type_id;
         $upload->filename = $filename . '.' . $ext;
         if (Koki::is_image('./uploads/' . $filename . '.' . $ext)) {
             $upload->small_filename = $filename . '_small' . '.' . $ext;
             $upload->thumb_filename = $filename . '_thumb' . '.' . $ext;
             $upload->image = 1;
         }
         $upload->extension = $ext;
         $upload->save();
         return $upload;
     }
 }
Ejemplo n.º 13
0
 public function action_upload()
 {
     $input = Input::all();
     if (isset($input['description'])) {
         $input['description'] = filter_var($input['description'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     }
     $rules = array('photo' => 'required|image|max:500', 'description' => 'required');
     $validation = Validator::make($input, $rules);
     if ($validation->fails()) {
         return Redirect::to('dashboard')->with_errors($validation);
     }
     $extension = File::extension($input['photo']['name']);
     $directory = path('public') . 'uploads/' . sha1(Auth::user()->id);
     $filename = sha1(Auth::user()->id . time()) . ".{$extension}";
     $upload_success = Input::upload('photo', $directory, $filename);
     if ($upload_success) {
         $photo = new Photo(array('location' => URL::to('uploads/' . sha1(Auth::user()->id) . '/' . $filename), 'description' => $input['description']));
         Auth::user()->photos()->insert($photo);
         Session::flash('status_success', 'Successfully uploaded your new Instapic');
     } else {
         Session::flash('status_error', 'An error occurred while uploading your new Instapic - please try again.');
     }
     return Redirect::to('dashboard');
 }
Ejemplo n.º 14
0
 /**
  * Function that handle with image upload when using refactor editor
  * @return json response with link for the image
  */
 public function post_redactorupload()
 {
     $rules = array('file' => 'image|max:100000');
     $path = path('base');
     $validation = Validator::make(Input::all(), $rules);
     $file = Input::file('file');
     if ($validation->fails()) {
         die("teste");
         //return FALSE;
     } else {
         if (Input::upload('file', 'public/images/projects', $file['name'])) {
             return Response::json(array('filelink' => URL::base() . '/images/projects/' . $file['name']));
         }
         return FALSE;
     }
 }
Ejemplo n.º 15
0
 public function post_uploadsetoran()
 {
     Input::upload('datasetoran', path('public'), 'upload.xlsx');
     $objPHPExcel = new PHPExcel();
     $objPHPExcel = PHPExcel_IOFactory::load(path('public') . 'upload.xlsx');
     $arrayst = array(1 => 7, 2 => 8, 3 => 9, 4 => 19, 5 => 12, 6 => 11, 7 => 16, 8 => 17, 9 => 13, 10 => 14, 11 => 21, 12 => 15, 13 => 10, 20 => 20);
     $startline = 8;
     foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
         $worksheetTitle = $worksheet->getTitle();
         $highestRow = $worksheet->getHighestRow();
         // e.g. 10
         $highestColumn = $worksheet->getHighestColumn();
         // e.g 'F'
         $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
         $nrColumns = ord($highestColumn) - 64;
         echo "<br>The worksheet " . $worksheetTitle . " has ";
         echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
         echo ' and ' . $highestRow . ' row.';
         echo '<br>Data: <table border="1"><tr>';
         for ($row = $startline; $row <= $highestRow; ++$row) {
             $cell = $worksheet->getCellByColumnAndRow(1, $row);
             $val = $cell->getValue();
             $checkin = Checkin::find($val);
             if ($checkin) {
                 foreach ($arrayst as $financial_type_id => $cellinexcell) {
                     $cell = $worksheet->getCellByColumnAndRow($cellinexcell, $row);
                     $val = $cell->getValue();
                     $payment = Checkinfinancial::where_checkin_id($checkin->id)->where_financial_type_id($financial_type_id)->first();
                     if ($payment) {
                         $payment->amount = $val;
                         $payment->save();
                     } else {
                         $payment = Checkinfinancial::create(array('checkin_id' => $checkin->id, 'financial_type_id' => $financial_type_id, 'amount' => $val));
                     }
                 }
                 echo '<tr>';
                 for ($col = 0; $col < $highestColumnIndex; ++$col) {
                     echo '<td>' . $val . ' ' . $col . '</td>';
                 }
                 echo '</tr>';
             }
         }
         echo '</table>';
     }
 }
Ejemplo n.º 16
0
 public function action_edit($id)
 {
     $method = Request::method();
     $user = Auth::user();
     $blog = Blog::find($id);
     if ($user->id != $blog->author->id) {
         return View::make('blog.view')->with('blog', $blog);
     }
     if ($method == 'POST') {
         // let's setup some rules for our new data
         // I'm sure you can come up with better ones
         $rules = array('title' => 'required|min:3|max:128', 'content' => 'required', 'file' => 'mimes:jpg,gif,png');
         //
         //Input::upload('picture', 'path/to/pictures', 'filename.ext');
         //File::cpdir($directory, $destination);
         //File::rmdir($directory);
         //echo File::mime('gif'); // outputs 'image/gif'
         //if (File::is('jpg', 'path/to/file.jpg'))
         //{
         //File::extension('picture.png');File::delete('path/to/file');
         //File::append('path/to/file', 'appended file content');
         //}File::put('path/to/file', 'file contents');$contents = File::get('path/to/file');
         // make the validator
         // let's get the new post from the POST data
         // this is much safer than using mass assignment
         $image = Input::file();
         $pictrue = '';
         $title = Input::get('title');
         $content = Input::get('content');
         $description = Input::get('title');
         if (empty($description)) {
             $description = substr($content, 0, 120);
         }
         $author_id = Input::get('author_id');
         $tags = Input::get('tags');
         if (!empty($image['file']['name'])) {
             $ext = File::extension($image['file']['name']);
             //$image['file']['tmp_name']
             Input::upload('file', path('public') . 'data', md5(date('YmdHis') . $image['file']['name']) . '.' . $ext);
             $pictrue = md5(date('YmdHis') . $image['file']['name']) . '.' . $ext;
         }
         $new_blog = array('title' => $title, 'description' => $description, 'content' => $content, 'author_id' => $author_id, 'views' => 0, 'pictrue' => $pictrue, 'tags' => $tags);
         $v = Validator::make($new_blog, $rules);
         if ($v->fails()) {
             // redirect back to the form with
             // errors, input and our currently
             // logged in user
             return Redirect::to('blog/add')->with('user', Auth::user())->with_errors($v)->with_input();
         }
         $blog->title = $title;
         $blog->description = $description;
         $blog->content = $content;
         $blog->author_id = $author_id;
         $blog->tags = $tags;
         if (!empty($pictrue)) {
             $blog->pictrue = $pictrue;
         }
         $blog->save();
         // redirect to viewing our new post
         return Redirect::to('blog/view/' . $blog->id);
     } else {
         // show the full view, and pass the post
         // we just aquired
         return View::make('blog.edit')->with('blog', $blog);
     }
 }
Ejemplo n.º 17
0
 public function action_imgUpload()
 {
     // $allowedExts = array("jpg", "jpeg", "gif", "png");
     // $temp = explode(".", $_FILES["file"]["name"]);
     // $extension = end($temp);
     // if ((($_FILES["file"]["type"] == "image/gif")
     // || ($_FILES["file"]["type"] == "image/jpeg")
     // || ($_FILES["file"]["type"] == "image/png")
     // || ($_FILES["file"]["type"] == "image/pjpeg"))
     // && ($_FILES["file"]["size"] < 200000000)
     // && in_array($extension, $allowedExts))
     //   {
     //   if ($_FILES["file"]["error"] > 0)
     //     {
     //     echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
     //     }
     //   else
     //     {
     //     echo "Upload: " . $_FILES["file"]["name"] . "<br>";
     //     echo "Type: " . $_FILES["file"]["type"] . "<br>";
     //     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
     //     echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
     //     if (file_exists("upload/" . $_FILES["file"]["name"]))
     //       {
     //       echo $_FILES["file"]["name"] . " already exists. ";
     //       }
     //     else
     //       {
     //       move_uploaded_file($_FILES["file"]["tmp_name"],
     //       "upload/" . $_FILES["file"]["name"]);
     //       echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
     //       }
     //     }
     //   }
     // else
     //   {
     //   echo "Invalid file";
     // }
     var_dump($_FILES);
     Input::upload('file', '/img/', $_FILES['file']['name']);
     echo realpath('/');
 }
Ejemplo n.º 18
0
 public static function add($pdf)
 {
     $tmp_name = sha1($pdf['pdf']['name'] . uniqid('', TRUE));
     Input::upload('pdf', path('storage') . 'pdfs', $tmp_name);
     return self::insert(array('tmp_name' => $tmp_name, 'title' => strip_tags($pdf['title']), 'description' => strip_tags($pdf['description']), 'file_name' => $pdf['pdf']['name'], 'size' => round($pdf['pdf']['size'] / 1024)));
 }
 /**
  * POST値で送られたファイルを保存する
  * @input   $file   str     保存ファイルのPOST名
  * @input   $name   str     保存先(パス名を含むファイル名)
  * @return  str
  */
 public static function saveFile($file, $path, $name)
 {
     Input::upload($file, $path, $name);
     $created = $path . '/' . $name;
     return $created;
 }