コード例 #1
0
ファイル: file.php プロジェクト: rcapp/kohana-jelly
 /**
  * Uploads a file if we have a valid upload
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @param   bool   $loaded
  * @return  string|NULL
  */
 public function save($model, $value, $loaded)
 {
     $original = $model->get($this->name, FALSE);
     // Upload a file?
     if (is_array($value) and upload::valid($value)) {
         if (FALSE !== ($filename = upload::save($value, NULL, $this->path))) {
             // Chop off the original path
             $value = str_replace($this->path, '', $filename);
             // Ensure we have no leading slash
             if (is_string($value)) {
                 $value = trim($value, '/');
             }
             // Delete the old file if we need to
             if ($this->delete_old_file and $original != $this->default) {
                 $path = $this->path . $original;
                 if (file_exists($path)) {
                     unlink($path);
                 }
             }
         } else {
             $value = $this->default;
         }
     }
     return $value;
 }
コード例 #2
0
ファイル: rest.php プロジェクト: andyst/gallery3
 public function __call($function, $args)
 {
     $input = Input::instance();
     $request = new stdClass();
     switch ($method = strtolower($input->server("REQUEST_METHOD"))) {
         case "get":
             $request->params = (object) $input->get();
             break;
         case "post":
             $request->params = (object) $input->post();
             if (isset($_FILES["file"])) {
                 $request->file = upload::save("file");
             }
             break;
     }
     $request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method));
     $request->access_token = $input->server("HTTP_X_GALLERY_REQUEST_KEY");
     $request->url = url::abs_current(true);
     rest::set_active_user($request->access_token);
     $handler_class = "{$function}_rest";
     $handler_method = $request->method;
     if (!method_exists($handler_class, $handler_method)) {
         throw new Rest_Exception("Bad Request", 400);
     }
     try {
         rest::reply(call_user_func(array($handler_class, $handler_method), $request));
     } catch (ORM_Validation_Exception $e) {
         foreach ($e->validation->errors() as $key => $value) {
             $msgs[] = "{$key}: {$value}";
         }
         throw new Rest_Exception("Bad Request: " . join(", ", $msgs), 400);
     }
 }
コード例 #3
0
ファイル: simple_uploader.php プロジェクト: krgeek/gallery3
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]");
     if ($file_validation->validate()) {
         // SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
         if (!batch::in_progress()) {
             batch::start();
         }
         $temp_filename = upload::save("Filedata");
         try {
             $name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $title = item::convert_filename_to_title($name);
             $path_info = pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
                 $movie = movie::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a movie"), html::anchor("movies/{$movie->id}", t("view movie")));
             } else {
                 $photo = photo::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a photo"), html::anchor("photos/{$photo->id}", t("view photo")));
             }
         } catch (Exception $e) {
             unlink($temp_filename);
             throw $e;
         }
         unlink($temp_filename);
     }
     print "File Received";
 }
コード例 #4
0
 /** 
  * Upload function for a JNCC style designations spreadsheet.
  */
 public function upload_csv()
 {
     try {
         // We will be using a POST array to send data, and presumably a FILES array for the
         // media.
         // Upload size
         $ups = Kohana::config('indicia.maxUploadSize');
         $_FILES = Validation::factory($_FILES)->add_rules('csv_upload', 'upload::valid', 'upload::required', 'upload::type[csv]', "upload::size[{$ups}]");
         if (count($_FILES) === 0) {
             echo "No file was uploaded.";
         } elseif ($_FILES->validate()) {
             if (array_key_exists('name_is_guid', $_POST) && $_POST['name_is_guid'] == 'true') {
                 $finalName = strtolower($_FILES['csv_upload']['name']);
             } else {
                 $finalName = time() . strtolower($_FILES['csv_upload']['name']);
             }
             $fTmp = upload::save('csv_upload', $finalName);
             url::redirect('taxon_designation/import_progress?file=' . urlencode(basename($fTmp)));
         } else {
             kohana::log('error', 'Validation errors uploading file ' . $_FILES['csv_upload']['name']);
             kohana::log('error', print_r($_FILES->errors('form_error_messages'), true));
             throw new ValidationError('Validation error', 2004, $_FILES->errors('form_error_messages'));
         }
     } catch (Exception $e) {
         $this->handle_error($e);
     }
 }
コード例 #5
0
ファイル: archivos1.php プロジェクト: sysdevbol/entidad
 public function action_archivos()
 {
     $errors = array();
     $id = $_GET['contra'];
     $proceso = ORM::factory('gestiones', $id);
     if ($_POST) {
         $id_archivo = 0;
         $archivo_texto = '';
         $post = Validation::factory($_FILES)->rule('archivo', 'Upload::not_empty')->rule('archivo', 'Upload::type', array(':value', array('jpg', 'png', 'gif', 'pdf', 'doc', 'docx', 'ppt', 'xls', 'xlsx')))->rule('archivo', 'Upload::size', array(':value', '3M'));
         // ->rules ( 'archivo', array (array ('Upload::valid' ), array ('Upload::type', array (':value', array ('pdf', 'doc', 'docx', 'ppt', 'xls', 'xlsx' ) ) ), array ('Upload::size', array (':value', '5M' ) ) ) );
         //si pasa la validacion guardamamos
         if ($post->check()) {
             //guardamos el archivo
             $filename = upload::save($_FILES['archivo1']);
             $archivo1 = ORM::factory('archivos1');
             //intanciamos el modelo
             $archivo1->archivo = basename($filename);
             $archivo1->extension = $_FILES['archivo']['type'];
             $archivo1->size = $_FILES['archivo']['size'];
             $archivo1->fecha = date('Y-m-d');
             $archivo1->proceso_id = $_POST['proceso_id'];
             // $archivo->id = $nuevo->id;
             $archivo->save();
             $_POST = array();
             //enviamos email
             // $this->template->content=View::factory('digitales');
         } else {
             $errors['Datos'] = 'No se pudo guardar, vuelva a intentarlo';
         }
     } else {
         $errors['Archivos'] = 'Ocurrio un error al subir el archivo';
     }
     $archivos = ORM::factory('archivos')->where('proceso_id', '=', $id)->find_all();
     $this->template->content = View::factory('Archivos')->bind('errors', $errors)->bind('proceso', $proceso)->bind('archivos', $archivos);
 }
コード例 #6
0
ファイル: Options.php プロジェクト: artbypravesh/morningpages
 public function action_index()
 {
     if ($_POST) {
         try {
             foreach ($_POST['option'] as $option_id => $value) {
                 $option = ORM::factory('Option', $option_id);
                 $option->value = $value;
                 $option->save();
             }
             if (arr::get($_FILES, 'option', false)) {
                 foreach ($_FILES['option']['name'] as $key => $file) {
                     $ext = $_FILES['option']['name'][$key];
                     $ext = explode('.', $ext);
                     $ext = end($ext);
                     $filename = upload::save(array('name' => $_FILES['option']['name'][$key], 'type' => $_FILES['option']['type'][$key], 'tmp_name' => $_FILES['option']['tmp_name'][$key], 'error' => $_FILES['option']['error'][$key], 'size' => $_FILES['option']['size'][$key]), 'option-' . $key . '.' . $ext, 'media/uploads');
                     $option = ORM::factory('Option', $key);
                     $option->value = 'option-' . $key . '.' . $ext;
                     $option->save();
                 }
             }
             ajax::success(__('Settings saved'));
         } catch (ORM_Validation_Exception $e) {
             ajax::error(__('An error occured and the settings couldn\'t be saved: :error', array(':error' => $e->getMessage())));
         }
     }
 }
コード例 #7
0
ファイル: MediaFile.php プロジェクト: swk/bluebox
 public function postSave()
 {
     $modified = $this->getModified(FALSE, TRUE);
     if ((array_key_exists('description', $modified) or array_key_exists('name', $modified)) and !$this->skip_desc_propagate) {
         $resampled = $this->get_resampled();
         foreach ($resampled as $key => $mediafile) {
             $differs = FALSE;
             if ($this->get('mediafile_id') == $mediafile['mediafile_id']) {
                 continue;
             }
             if ($this->get('description') != $mediafile['description']) {
                 $differs = TRUE;
                 $resampled[$key]['description'] = $this->get('description');
             }
             if ($this->get('name') != $mediafile['name']) {
                 $differs = TRUE;
                 $resampled[$key]['name'] = $this->get('name');
             }
             if (!$differs) {
                 continue;
             }
             kohana::log('debug', 'Copy media file description or name from ' . $this->get('mediafile_id') . ' to ' . $mediafile['mediafile_id']);
             $mediafile->skip_desc_propagate = TRUE;
             $resampled[$key]->save();
             $mediafile->skip_desc_propagate = FALSE;
         }
     }
     if (!$this->uploaded_file) {
         return;
     }
     kohana::log('debug', 'Moving upload "' . $this->uploaded_file['tmp_name'] . '" to "' . $this->filepath(TRUE) . '"');
     if (!upload::save($this->uploaded_file, $this->get('file'), $this->filepath())) {
         throw new Exception('Unable to save file to system');
     }
 }
コード例 #8
0
 function save($id = null, $data)
 {
     global $osC_Database, $osC_Language, $osC_Image;
     if (is_numeric($id)) {
         foreach ($osC_Language->getAll() as $l) {
             $image_upload = new upload('image' . $l['id'], DIR_FS_CATALOG . 'images/');
             if ($image_upload->exists() && $image_upload->parse() && $image_upload->save()) {
                 $Qdelete = $osC_Database->query('select image from :table_slide_images where image_id = :image_id and language_id=:language_id');
                 $Qdelete->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
                 $Qdelete->bindInt(':image_id', $id);
                 $Qdelete->bindValue(':language_id', $l['id']);
                 $Qdelete->execute();
                 if ($Qdelete->numberOfRows() > 0) {
                     @unlink(DIR_FS_CATALOG . 'images/' . $Qdelete->value('image'));
                 }
                 $Qimage = $osC_Database->query('update :table_slide_images set image = :image, description = :description, image_url = :image_url, sort_order = :sort_order, status = :status where image_id = :image_id and language_id=:language_id');
                 $Qimage->bindValue(':image', $image_upload->filename);
             } else {
                 $Qimage = $osC_Database->query('update :table_slide_images set description = :description, image_url = :image_url, sort_order = :sort_order, status = :status where image_id = :image_id and language_id=:language_id');
             }
             $Qimage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
             $Qimage->bindValue(':description', $data['description'][$l['id']]);
             $Qimage->bindValue(':image_url', $data['image_url'][$l['id']]);
             $Qimage->bindValue(':sort_order', $data['sort_order']);
             $Qimage->bindValue(':status', $data['status']);
             $Qimage->bindInt(':image_id', $id);
             $Qimage->bindValue(':language_id', $l['id']);
             $Qimage->execute();
         }
     } else {
         $Qmaximage = $osC_Database->query('select max(image_id) as image_id from :table_slide_images');
         $Qmaximage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
         $Qmaximage->execute();
         $image_id = $Qmaximage->valueInt('image_id') + 1;
         foreach ($osC_Language->getAll() as $l) {
             $products_image = new upload('image' . $l['id'], DIR_FS_CATALOG . 'images/');
             if ($products_image->exists() && $products_image->parse() && $products_image->save()) {
                 $Qimage = $osC_Database->query('insert into :table_slide_images (image_id,language_id ,description,image ,image_url ,sort_order,status) values (:image_id,:language_id,:description ,:image,:image_url ,:sort_order,:status)');
                 $Qimage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
                 $Qimage->bindValue(':image_id', $image_id);
                 $Qimage->bindValue(':language_id', $l['id']);
                 $Qimage->bindValue(':description', $data['description'][$l['id']]);
                 $Qimage->bindValue(':image', $products_image->filename);
                 $Qimage->bindValue(':image_url', $data['image_url'][$l['id']]);
                 $Qimage->bindValue(':sort_order', $data['sort_order']);
                 $Qimage->bindValue(':status', $data['status']);
                 $Qimage->execute();
             }
         }
     }
     if ($osC_Database->isError()) {
         return false;
     } else {
         osC_Cache::clear('slide-images');
         return true;
     }
 }
コード例 #9
0
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     // The Flash uploader not call /start directly, so simulate it here for now.
     if (!batch::in_progress()) {
         batch::start();
     }
     $form = $this->_get_add_form($album);
     // Uploadify adds its own field to the form, so validate that separately.
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::required", "upload::type[" . implode(",", legal_file::get_extensions()) . "]");
     if ($form->validate() && $file_validation->validate()) {
         $temp_filename = upload::save("Filedata");
         Event::add("system.shutdown", create_function("", "unlink(\"{$temp_filename}\");"));
         try {
             $item = ORM::factory("item");
             $item->name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $item->title = item::convert_filename_to_title($item->name);
             $item->parent_id = $album->id;
             $item->set_data_file($temp_filename);
             // Remove double extensions from the filename - they'll be disallowed in the model but if
             // we don't do it here then it'll result in a failed upload.
             $item->name = legal_file::smash_extensions($item->name);
             $path_info = @pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), legal_file::get_movie_extensions())) {
                 $item->type = "movie";
                 $item->save();
                 log::success("content", t("Added a movie"), html::anchor("movies/{$item->id}", t("view movie")));
             } else {
                 $item->type = "photo";
                 $item->save();
                 log::success("content", t("Added a photo"), html::anchor("photos/{$item->id}", t("view photo")));
             }
             module::event("add_photos_form_completed", $item, $form);
         } catch (Exception $e) {
             // The Flash uploader has no good way of reporting complex errors, so just keep it simple.
             Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
             // Ugh.  I hate to use instanceof, But this beats catching the exception separately since
             // we mostly want to treat it the same way as all other exceptions
             if ($e instanceof ORM_Validation_Exception) {
                 Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1));
             }
             header("HTTP/1.1 500 Internal Server Error");
             print "ERROR: " . $e->getMessage();
             return;
         }
         print "FILEID: {$item->id}";
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid upload");
     }
 }
コード例 #10
0
ファイル: dlslider.php プロジェクト: natgeo/kids-myshot
 public function action_save($pid = null)
 {
     $data = (object) filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
     $photo = ORM::factory("dlsliderphoto", $pid);
     $slider = ORM::factory("dlslidergroup", $data->slider_id);
     $new = empty($photo->id);
     if (!$slider->loaded()) {
         Message::set(Message::ERROR, "Something unexpected happened. Please try again.");
         $this->request->redirect("admin/dlslider/");
         return;
     }
     $files = Validate::factory($_FILES);
     $files->rule('photo', 'Upload::type', array(array('jpg', 'png', 'gif')));
     foreach ($data as $val) {
         if (empty($val)) {
             Message::set(Message::ERROR, "All fields must be filled in.");
             $this->request->redirect("admin/dlslider/edit/{$slider->id}");
             return;
         }
     }
     $photo->title = $data->title;
     $photo->teaser = $data->teaser;
     $photo->link_text = $data->linktext;
     $photo->link = $data->link;
     $photo->saved = isset($data->save) ? 1 : 0;
     if (empty($photo->position)) {
         $photo->position = $slider->allPhotos->count() + 1;
     }
     if ($files->check()) {
         if ($_FILES['photo']['error'] == 0) {
             $filename = upload::save($_FILES['photo'], $_FILES['photo']['name'], Kohana::config('myshot.relativeBase'));
             // New file name
             $new_filename = rand(0, 1000) . "_" . substr($_FILES['photo']['name'], 0, strlen($_FILES['photo']['name']) - 4) . '-resized' . substr($_FILES['photo']['name'], -4);
             $localFile = Kohana::config('myshot.relativeBase') . $new_filename;
             // Resize, sharpen, and save the image
             Image::factory($filename)->resize(Model_DLSliderPhoto::WIDTH, Model_DLSliderPhoto::HEIGHT, Image::WIDTH)->crop(Model_DLSliderPhoto::WIDTH, Model_DLSliderPhoto::HEIGHT, 0, 0)->save($localFile);
             Library_Akamai::factory()->addToDir($localFile, "dlslider", date("Y-m"));
             $photo->filename = "dlslider/" . date("Y-m") . "/{$new_filename}";
             // Remove the temporary files
             unlink($filename);
             unlink($localFile);
         }
     }
     if (empty($photo->filename)) {
         Message::set(Message::ERROR, "Something was wrong with the file to upload. Please check the file try again.");
         $this->request->redirect("admin/dlslider/edit/{$slider->id}");
         return;
     }
     $photo->save();
     if ($new) {
         DB::update("dl_slider_group_dl_slider_photos")->set(array("position" => $slider->allPhotos->count()))->where("dl_slider_group_id", "=", $slider->id)->where("dl_slider_photos_id", "=", $photo->id)->execute();
     }
     !$slider->has("photos", $photo) ? $slider->add("photos", $photo) : null;
     Message::set(Message::SUCCESS, "Image Added");
     $this->request->redirect("admin/dlslider/edit/{$slider->id}");
 }
コード例 #11
0
 function storeFileUpload($file, $directory)
 {
     if (is_writeable($directory)) {
         $upload = new upload($file, $directory);
         if ($upload->exists() && $upload->parse() && $upload->save()) {
             return true;
         }
     }
     return false;
 }
コード例 #12
0
 function execute()
 {
     global $osC_Session, $osC_Product, $toC_Customization_Fields, $osC_Language, $messageStack;
     if (!isset($osC_Product)) {
         $id = false;
         foreach ($_GET as $key => $value) {
             if ((ereg('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && $key != $osC_Session->getName()) {
                 $id = $key;
             }
             break;
         }
         if ($id !== false && osC_Product::checkEntry($id)) {
             $osC_Product = new osC_Product($id);
         }
     }
     if (isset($osC_Product)) {
         $errors = array();
         $data = array();
         $customizations = $osC_Product->getCustomizations();
         foreach ($customizations as $field) {
             $fields_id = $field['customization_fields_id'];
             if ($field['type'] == CUSTOMIZATION_FIELD_TYPE_INPUT_TEXT) {
                 $value = isset($_POST['customizations'][$fields_id]) ? $_POST['customizations'][$fields_id] : null;
                 if ($field['is_required'] && $value == null) {
                     $messageStack->add_session('products_customizations', sprintf($osC_Language->get('error_customization_field_must_be_specified'), $field['name']), 'error');
                 } else {
                     if ($value != null) {
                         $data[$fields_id] = array('customization_fields_id' => $field['customization_fields_id'], 'customization_fields_name' => $field['name'], 'customization_type' => CUSTOMIZATION_FIELD_TYPE_INPUT_TEXT, 'customization_value' => $value);
                     }
                 }
             } else {
                 $file = new upload('customizations_' . $fields_id, DIR_FS_CACHE . '/products_customizations/');
                 if ($field['is_required'] && !$file->exists() && !$toC_Customization_Fields->hasCustomizationField($osC_Product->getID(), $fields_id)) {
                     $messageStack->add_session('products', sprintf($osC_Language->get('error_customization_field_must_be_specified'), $field['name']), 'error');
                 } else {
                     if ($file->exists()) {
                         if ($file->parse() && $file->save()) {
                             $filename = $file->filename;
                             $cache_filename = md5($filename . time());
                             rename(DIR_FS_CACHE . '/products_customizations/' . $filename, DIR_FS_CACHE . '/products_customizations/' . $cache_filename);
                             $data[$fields_id] = array('customization_fields_id' => $field['customization_fields_id'], 'customization_fields_name' => $field['name'], 'customization_type' => CUSTOMIZATION_FIELD_TYPE_INPUT_FILE, 'customization_value' => $filename, 'cache_filename' => $cache_filename);
                         } else {
                             $messageStack->add_session('products_customizations', $file->getLastError(), 'error');
                         }
                     }
                 }
             }
         }
         //var_dump($data);exit;
         if ($messageStack->size('products_customizations') === 0) {
             $toC_Customization_Fields->set($osC_Product->getID(), $data);
         }
     }
     osc_redirect(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getID()));
 }
コード例 #13
0
ファイル: rest.php プロジェクト: HarriLu/gallery3
 public function __call($function, $args)
 {
     try {
         $input = Input::instance();
         $request = new stdClass();
         switch ($method = strtolower($input->server("REQUEST_METHOD"))) {
             case "get":
                 $request->params = (object) $input->get();
                 break;
             default:
                 $request->params = (object) $input->post();
                 if (isset($_FILES["file"])) {
                     $request->file = upload::save("file");
                     system::delete_later($request->file);
                 }
                 break;
         }
         if (isset($request->params->entity)) {
             $request->params->entity = json_decode($request->params->entity);
         }
         if (isset($request->params->members)) {
             $request->params->members = json_decode($request->params->members);
         }
         $request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method));
         $request->access_key = $input->server("HTTP_X_GALLERY_REQUEST_KEY");
         if (empty($request->access_key) && !empty($request->params->access_key)) {
             $request->access_key = $request->params->access_key;
         }
         $request->url = url::abs_current(true);
         if ($suffix = Kohana::config('core.url_suffix')) {
             $request->url = substr($request->url, 0, strlen($request->url) - strlen($suffix));
         }
         rest::set_active_user($request->access_key);
         $handler_class = "{$function}_rest";
         $handler_method = $request->method;
         if (!class_exists($handler_class) || !method_exists($handler_class, $handler_method)) {
             throw new Rest_Exception("Bad Request", 400);
         }
         $response = call_user_func(array($handler_class, $handler_method), $request);
         if ($handler_method == "post") {
             // post methods must return a response containing a URI.
             header("HTTP/1.1 201 Created");
             header("Location: {$response['url']}");
         }
         rest::reply($response);
     } catch (ORM_Validation_Exception $e) {
         // Note: this is totally insufficient because it doesn't take into account localization.  We
         // either need to map the result values to localized strings in the application code, or every
         // client needs its own l10n string set.
         throw new Rest_Exception("Bad Request", 400, $e->validation->errors());
     } catch (Kohana_404_Exception $e) {
         throw new Rest_Exception("Not Found", 404);
     }
 }
コード例 #14
0
ファイル: archivo.php プロジェクト: sysdevbol/entidad
 public function action_lista()
 {
     $errors = array();
     $id = $_GET['contra'];
     $tipo = $_GET['tipo'];
     switch ($tipo) {
         case 3:
             $proceso = ORM::factory('gestiones', $id);
             $nombre = $proceso->numContratacion;
             break;
         case 2:
             $proceso = ORM::factory('viviendas', $id);
             $nombre = $proceso->serDocumental;
             break;
         default:
             $proceso = ORM::factory('centrales', $id);
             $nombre = 'Serie Documental: ' . $proceso->serDocumental;
             break;
     }
     if ($_POST) {
         $id_archivo = 0;
         $archivo_texto = '';
         $post = Validation::factory($_FILES)->rule('archivo', 'Upload::not_empty')->rule('archivo', 'Upload::type', array(':value', array('pdf', 'doc', 'docx', 'xlsx')))->rule('archivo', 'Upload::size', array(':value', '3M'));
         // ->rules ( 'archivo', array (array ('Upload::valid' ), array ('Upload::type', array (':value', array ('pdf', 'doc', 'docx', 'ppt', 'xls', 'xlsx' ) ) ), array ('Upload::size', array (':value', '5M' ) ) ) );
         //si pasa la validacion guardamamos
         if ($post->check()) {
             //guardamos el archivo
             $filename = upload::save($_FILES['archivo']);
             $archivo = ORM::factory('aarchivos');
             //intanciamos el modelo
             $archivo->archivo = basename($filename);
             $archivo->extension = $_FILES['archivo']['type'];
             $archivo->size = $_FILES['archivo']['size'];
             $archivo->fecha = date('Y-m-d H:i:s');
             $archivo->proceso_id = $_POST['proceso_id'];
             $archivo->central_id = $tipo;
             $archivo->user_id = $this->template->user->id;
             // $archivo->id = $nuevo->id;
             $archivo->save();
             $_POST = array();
             //enviamos email
             // $this->template->content=View::factory('digitales');
         } else {
             $errors['Datos'] = 'No se pudo guardar, vuelva a intentarlo';
         }
     } else {
         $errors['Archivos'] = 'Ocurrio un error al subir el archivo';
     }
     //obentemos los archivos dato el tipo y el proceso
     $archivos = ORM::factory('aarchivos')->where('proceso_id', '=', $id)->where('central_id', '=', $tipo)->find_all();
     $this->template->content = View::factory('archivero/lista_archivos')->bind('errors', $errors)->bind('proceso', $proceso)->bind('nombre', $nombre)->bind('archivos', $archivos);
 }
コード例 #15
0
ファイル: gift_certs.php プロジェクト: rrecurse/IntenseCart
 function get_upload_file($fld)
 {
     global $UploadCache;
     if (!isset($UploadCache)) {
         $UploadCache = array();
     }
     if (!isset($UploadCache[$fld])) {
         $model_image_obj = new upload($fld);
         $model_image_obj->set_destination(DIR_FS_CATALOG_IMAGES);
         $UploadCache[$fld] = $model_image_obj->parse() && $model_image_obj->save() ? $model_image_obj->filename : '';
     }
     //echo 'get_upload_file('.$fld.")=".$UploadCache[$fld]."\n";
     return $UploadCache[$fld];
 }
コード例 #16
0
ファイル: web_upload.php プロジェクト: sayi21cn/ttae_open
 function upload($file)
 {
     global $_G;
     if (!class_exists('upload')) {
         include ROOT_PATH . 'web/upload.class.php';
     }
     if (!is_array($file)) {
         $file = $this->file;
     }
     $upload = new upload();
     $img_arr = $attach = array();
     $upload_path = '/assets/uploads/';
     $rs = $upload->init($file, $upload_path);
     if (!$rs) {
         return false;
     }
     $attach =& $upload->attach;
     if ($attach['extension'] != 'jpg' && $attach['extension'] != 'png') {
         $this->file_type = '.' . $attach['extension'];
         $this->__construct();
     }
     if ($attach['extension'] == 'attach' && $attach['isimage'] != 1) {
         $this->msg = '上传的文件非图片';
         L($this->msg);
         @unlink($attach['tmp_name']);
         return false;
         //非可上传的文件,就禁止上传了
     }
     $upload_max_size = $_G['setting']['upload_max_size'] ? intval($_G['setting']['upload_max_size']) : 2;
     if ($attach['size'] > 1024 * 1024 * $upload_max_size) {
         $this->msg = '上传文件失败,系统设置最大上传大为:' . $upload_max_size . 'MB';
         L($this->msg);
         @unlink($attach['tmp_name']);
         return false;
     }
     if ($attach['errorcode']) {
         $this->msg = '上传图片失败' . errormessage();
         @unlink($attach['tmp_name']);
         L($this->msg);
         return false;
     }
     $lang_path = ROOT_PATH . $upload_path . $this->dir2;
     if (!is_dir($lang_path)) {
         dmkdir($lang_path);
     }
     $attach['target'] = $lang_path . $this->name;
     $upload->save();
     return $upload_path . $this->dir2 . $this->name;
 }
コード例 #17
0
ファイル: upload.php プロジェクト: googlecode-mirror/s7ncms
 public function save()
 {
     $this->auto_render = FALSE;
     $files = Validation::factory($_FILES)->add_rules('picture', 'upload::valid', 'upload::required', 'upload::type[gif,jpg,png,jpeg]', 'upload::size[4M]');
     echo '<script language="javascript" type="text/javascript">';
     if ($files->validate()) {
         $filename = upload::save('picture');
         echo 'window.top.window.stopUploadSuccess("' . url::base() . 'upload/' . basename($filename) . '");';
     } else {
         $errors = $files->errors();
         echo 'window.top.window.stopUploadError("' . $errors['picture'] . '");';
     }
     echo '</script>';
     exit;
 }
コード例 #18
0
ファイル: simple_uploader.php プロジェクト: viosca/gallery3
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]");
     if ($file_validation->validate()) {
         // SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
         if (!batch::in_progress()) {
             batch::start();
         }
         $temp_filename = upload::save("Filedata");
         try {
             $name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $title = item::convert_filename_to_title($name);
             $path_info = @pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
                 $item = movie::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a movie"), html::anchor("movies/{$item->id}", t("view movie")));
             } else {
                 $item = photo::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a photo"), html::anchor("photos/{$item->id}", t("view photo")));
             }
             // We currently have no way of showing errors if validation fails, so only call our event
             // handlers if validation passes.
             $form = $this->_get_add_form($album);
             if ($form->validate()) {
                 module::event("add_photos_form_completed", $item, $form);
             }
         } catch (Exception $e) {
             Kohana_Log::add("alert", $e->__toString());
             if (file_exists($temp_filename)) {
                 unlink($temp_filename);
             }
             header("HTTP/1.1 500 Internal Server Error");
             print "ERROR: " . $e->getMessage();
             return;
         }
         unlink($temp_filename);
         print "FILEID: {$item->id}";
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid Upload");
     }
 }
コード例 #19
0
ファイル: settings.php プロジェクト: sydlawrence/SocialFeed
 private function __upload_logo()
 {
     $_FILES = Validation::factory($_FILES)->add_rules('file', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[2M]');
     unlink(DOCROOT . 'zest/images/logo.jpg');
     // Temporary file name
     $filename = upload::save('file');
     // Resize, sharpen, and save the image
     $img = Image::factory($filename);
     $img->resize(150, 80, Image::AUTO);
     $img->save(DOCROOT . 'zest/images/logo.jpg');
     // Remove the temporary file
     unlink($filename);
     $this->__throw_success("The image has been successfully uploaded!");
     $this->__throw_warning("If the logo appears to be unchanged, the logo will change next time you login.");
     return true;
 }
コード例 #20
0
ファイル: admin_config.php プロジェクト: vobinh/PHP
 protected function _save_img_bg($image)
 {
     if (!upload::valid($image) or !upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
         $this->session->set_flash('error_msg', 'Only upload file jpg , jpeg , png , gif');
         url::redirect('admin_config');
     } else {
         $directory = DOCROOT . 'themes/client/styleSIC/index/pics/';
         if ($file = upload::save($image, NULL, $directory)) {
             $filename = 'bg_' . md5(rand(0, 999)) . time() . '.png';
             Image::factory($file)->save($directory . $filename);
             // Delete the temporary file
             unlink($file);
             return $filename;
         }
         return FALSE;
     }
 }
コード例 #21
0
ファイル: file.php プロジェクト: jerfowler/kohana-jelly
 /**
  * Uploads a file if we have a valid upload
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @param   bool   $loaded
  * @return  string|NULL
  */
 public function save($model, $value, $loaded)
 {
     // Upload a file?
     if (is_array($value) and upload::valid($value)) {
         if (FALSE !== ($filename = upload::save($value, NULL, $this->path))) {
             // Chop off the original path
             $value = str_replace(realpath($this->path) . DIRECTORY_SEPARATOR, '', $filename);
             // Ensure we have no leading slash
             if (is_string($value)) {
                 $value = trim($value, DIRECTORY_SEPARATOR);
             }
         } else {
             $value = $this->default;
         }
     }
     return $value;
 }
コード例 #22
0
 public static function save($id = null, $data)
 {
     global $osC_Database;
     $error = false;
     if (empty($data['html_text']) && empty($data['image_local']) && !empty($data['image'])) {
         $image = new upload($data['image'], realpath('../images/' . $data['image_target']));
         if (!$image->exists() || !$image->parse() || !$image->save()) {
             $error = true;
         }
     }
     if ($error === false) {
         $image_location = !empty($data['image_local']) ? $data['image_local'] : (isset($image) ? $data['image_target'] . $image->filename : null);
         if (is_numeric($id)) {
             $Qbanner = $osC_Database->query('update :table_banners set banners_title = :banners_title, banners_url = :banners_url, banners_image = :banners_image, banners_group = :banners_group, banners_html_text = :banners_html_text, expires_date = :expires_date, expires_impressions = :expires_impressions, date_scheduled = :date_scheduled, status = :status where banners_id = :banners_id');
             $Qbanner->bindInt(':banners_id', $id);
         } else {
             $Qbanner = $osC_Database->query('insert into :table_banners (banners_title, banners_url, banners_image, banners_group, banners_html_text, expires_date, expires_impressions, date_scheduled, status, date_added) values (:banners_title, :banners_url, :banners_image, :banners_group, :banners_html_text, :expires_date, :expires_impressions, :date_scheduled, :status, now())');
         }
         $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
         $Qbanner->bindValue(':banners_title', $data['title']);
         $Qbanner->bindValue(':banners_url', $data['url']);
         $Qbanner->bindValue(':banners_image', $image_location);
         $Qbanner->bindValue(':banners_group', !empty($data['group_new']) ? $data['group_new'] : $data['group']);
         $Qbanner->bindValue(':banners_html_text', $data['html_text']);
         if (empty($data['date_expires'])) {
             $Qbanner->bindRaw(':expires_date', 'null');
             $Qbanner->bindInt(':expires_impressions', $data['expires_impressions']);
         } else {
             $Qbanner->bindValue(':expires_date', $data['date_expires']);
             $Qbanner->bindInt(':expires_impressions', 0);
         }
         if (empty($data['date_scheduled'])) {
             $Qbanner->bindRaw(':date_scheduled', 'null');
             $Qbanner->bindInt(':status', $data['status'] === true ? 1 : 0);
         } else {
             $Qbanner->bindValue(':date_scheduled', $data['date_scheduled']);
             $Qbanner->bindInt(':status', $data['date_scheduled'] > date('Y-m-d') ? 0 : ($data['status'] === true ? 1 : 0));
         }
         $Qbanner->setLogging($_SESSION['module'], $id);
         $Qbanner->execute();
         if (!$osC_Database->isError()) {
             return true;
         }
     }
     return false;
 }
コード例 #23
0
 /**
  * get full information for an upload
  *
  * @param string $file 
  * @param array $file_data 
  * @return array
  * @author Andy Bennett
  */
 function get_upload_data($file, $file_data, $save = true)
 {
     $filename = $save ? upload::save($file_data) : $file;
     if (!strlen($filename)) {
         throw new Exception("Empty filename", 1);
     }
     $pp = pathinfo($filename);
     $ext = strtolower($pp['extension']);
     $file_type = uploads::check_filetype($file_data['type'], $filename, $ext);
     $d = Kohana::config('upload.directory');
     $upload_data['file_name'] = $pp['basename'];
     $upload_data['file_type'] = $file_type;
     $upload_data['file_path'] = $d;
     $upload_data['full_path'] = $filename;
     $upload_data['raw_name'] = $pp['filename'];
     $upload_data['orig_name'] = $file_data['name'];
     $upload_data['file_ext'] = '.' . strtolower($ext);
     $upload_data['file_size'] = $file_data['size'];
     $upload_data['is_image'] = file::is_image($file_type);
     $upload_data['is_video'] = 0;
     $upload_data['is_audio'] = 0;
     $upload_data['date_added'] = date('Y-m-d H:i:s');
     $upload_data['preview'] = false;
     $driver = uploads::get_driver($upload_data['is_image'], $file_type, $ext);
     if ($driver !== false) {
         // Load the driver
         if (Kohana::auto_load($driver)) {
             // Initialize the driver
             $upload_driver = new $driver();
             // Validate the driver
             if (!$upload_driver instanceof Uploader_Driver) {
                 throw new Kohana_Exception('core.driver_implements', $driver, 'upload', 'Uploader_Driver');
             }
             $upload_driver->generate_preview($upload_data, $filename, $ext);
         }
     }
     if ($upload_data['is_image']) {
         $properties = file::get_image_properties($filename);
         if (!empty($properties)) {
             $upload_data = array_merge($upload_data, $properties);
         }
     }
     return $upload_data;
 }
コード例 #24
0
ファイル: gallery.php プロジェクト: repli2dev/re-eshop
 /**
  * Add image to item
  * @return void
  * @param integer id of item
  * @param string dir with images
  */
 public function add_image($item, $dir)
 {
     // Check for user permission
     if (user::is_got()) {
         $this->set_title(Kohana::lang('gallery.add_image'));
         $this->add_breadcrumb(Kohana::lang('gallery.add_image'), url::current());
         // Set redirect URL
         if (isset($_POST['redirect'])) {
             $redirect = $_POST['redirect'];
         } else {
             $redirect = request::referrer();
         }
         $form = array('image' => '', 'redirect' => $redirect);
         $errors = array();
         if (isset($_FILES)) {
             $files = new Validation($_FILES);
             // Rules
             $files->add_rules('image', 'upload::valid', 'upload::required', 'upload::type[jpg,jpeg]', 'upload::size[500K]');
             if ($files->validate()) {
                 // Temporary file
                 $filename = upload::save('image');
                 // Get new name
                 $id = gallery::get_image_new_name($item, $dir);
                 // Save original and thumb
                 Image::factory($filename)->save('./data/' . $dir . '/' . $item . '_' . $id . '.jpg');
                 Image::factory($filename)->resize(128, 128, Image::AUTO)->quality(85)->save('./data/' . $dir . '/' . $item . '_' . $id . '_m.jpg');
                 // Remove the temporary file
                 unlink($filename);
                 url::redirect($form['redirect']);
             } else {
                 // Repopulate form with error and original values
                 $form = arr::overwrite($form, $files->as_array());
                 $errors = $files->errors('gallery_errors');
             }
         }
         // View
         $this->template->content = new View('admin/add_image');
         $this->template->content->errors = $errors;
         $this->template->content->form = $form;
     } else {
         url::redirect('/denied');
     }
 }
コード例 #25
0
ファイル: MY_upload.php プロジェクト: ready4god2513/scs
 /**
  * Upload an image and return the filename.
  * Will change the post field to the URL of the image after saving.
  * @Developer brandon
  * @Date Apr 20, 2010
  * @Param (string) $post_field
  * @Param (string) $directory
  * @Param (int) $width
  * @Param (int) $height
  * @Return (any) (either the filename that was saved, or false if couldn't save)
  */
 public static function process($post_field = 'image', $directory = NULL, $width = 100, $height = 100)
 {
     $files = Validation::factory($_FILES)->add_rules($post_field, 'upload::valid', 'upload::required', 'upload::type[gif,jpg,png]');
     if ($files->validate()) {
         // Temporary file name
         $filename = upload::save($post_field);
         $new_filename = preg_replace('/[^0-9a-zA-Z_.]/', '', basename($filename));
         // Resize, sharpen, and save the image
         Image::factory($filename)->resize($width, $height, Image::WIDTH)->crop($width, $height)->save(Kohana::config('upload.directory') . $directory . $new_filename);
         // Remove the temporary file
         unlink($filename);
         // Set the post field
         $_POST[$post_field] = $new_filename;
         return $new_filename;
     } else {
         unset($_POST[$post_field]);
         return false;
     }
 }
コード例 #26
0
 function upimg($imagefile)
 {
     $this->file_type = $imagefile['type'];
     if (!($this->file_type != 'image/jpg' && $this->file_type != 'image/x-png' && $this->file_type != 'image/pjpeg' && $this->file_type != 'image/jpeg' && $this->file_type != 'image/gif' && $this->file_type != 'image/png')) {
         //Execute IF statment
         try {
             $retupload = upload::save($imagefile);
         } catch (Exception $e) {
             echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
             die;
         }
         $retupload = explode('upload/', $retupload);
         if (count($retupload) > 1) {
             $retupload = $retupload[1];
             //                     basics::thlizer($retupload);
             //                     echo Kohana::debug($retupload);
             return $retupload;
         }
     }
 }
コード例 #27
0
ファイル: admin.php プロジェクト: purplexcite/seagifts
 function editgood()
 {
     $data = Validate::factory(array_merge($_POST, $_FILES))->label('edit_name', 'наименование')->label('edit_id', 'id')->label('edit_price', 'цена')->rule('edit_name', 'not_empty')->rule('edit_price', 'not_empty')->rule('edit_id', 'not_empty')->label('edit_photo', 'фото')->rule('edit_photo', 'upload::type', array(array('gif', 'png', 'jpg')));
     if ($data->check()) {
         for ($i = 0; $i < count($_POST['edit_id']); $i++) {
             // If new photo exist
             if (!empty($_FILES['edit_photo']['name'][$i])) {
                 echo Kohana::debug($_FILES);
                 $arr = array('edit_photo' => array('name' => $_FILES['edit_photo']['name'][$i], 'type' => $_FILES['edit_photo']['type'][$i], 'tmp_name' => $_FILES['edit_photo']['tmp_name'][$i], 'error' => $_FILES['edit_photo']['error'][$i], 'size' => $_FILES['edit_photo']['size'][$i]));
                 $photo = upload::save($arr['edit_photo'], $_FILES['edit_photo']['name'][$i]);
                 DB::update('goods')->set(array('name' => $_POST['edit_name'][$i], 'price' => $_POST['edit_price'][$i], 'description' => $_POST['edit_description'][$i], 'photo' => $_FILES['edit_photo']['name'][$i]))->where('id', '=', $_POST['edit_id'][$i])->execute();
             } else {
                 DB::update('goods')->set(array('name' => $_POST['edit_name'][$i], 'description' => $_POST['edit_description'][$i], 'price' => $_POST['edit_price'][$i]))->where('id', '=', $_POST['edit_id'][$i])->execute();
             }
         }
         return TRUE;
     } else {
         return strtolower(implode(' и ', $data->errors('')));
     }
 }
コード例 #28
0
ファイル: slides.php プロジェクト: VinceOmega/mcb-nov-build
 public function add()
 {
     if (isset($_POST['save'])) {
         $post = new Validation(array_merge($_POST, $_FILES));
         if (!$post->validate()) {
             $errors = $post->errors('form_errors');
             foreach ($errors as $error) {
                 echo '<p class="error">' . $error . '</p>';
             }
         } else {
             $id = $this->uri->segment(3);
             $slide = ORM::factory('slide')->find($id);
             $slide->image_alt = $post->image_alt;
             $slide->order = $post->order;
             $slide->url = $post->url;
             $slide->site_id = $post->site_id;
             if (!empty($_FILES['image']['name'])) {
                 // uses Kohana upload helper
                 $_FILES = Validation::factory($_FILES)->add_rules('image', 'upload::valid', 'upload::type[gif,jpg,jpeg,png]', 'upload::size[2M]');
                 if ($_FILES->validate()) {
                     // Temporary file name
                     $dat = time();
                     $filename = upload::save('image', basename($_FILES['image']['tmp_name']));
                     $file = $dat . '-' . basename($_FILES['image']['name']);
                     // Resize, sharpen, and save the image
                     Image::factory($filename)->save(DOCROOT . '../../env/images/mcc/slideshow/' . $file, FALSE);
                     // Remove the temporary file
                     unlink($filename);
                     $slide->image = $file;
                 } else {
                     $errors = $_FILES->errors('form_user');
                 }
             }
             $slide->save();
             url::redirect('/slides/edit/' . $slide->id);
         }
     }
     $this->_renderView();
 }
コード例 #29
0
ファイル: helper.php プロジェクト: TdroL/kohana-jelly-torn
 public function upload()
 {
     if (!$_FILES) {
         return;
     }
     $surfix = Kohana::config('torn')->surfix->temp;
     $surfix_len = utf8::strlen($surfix);
     foreach ($_POST as $key => $tmp_name) {
         if (utf8::substr($key, -$surfix_len) == $surfix) {
             $field = utf8::substr($key, 0, -$surfix_len);
             $this->parent->model->set($field, $tmp_name);
         }
     }
     $cache = Cache::instance();
     foreach ($_FILES as $key => $upload) {
         $this->parent->model->set($key, $upload);
         if (!isset($this->parent->fields[$key]) or !$this->parent->fields[$key] instanceof Torn_Field_File) {
             continue;
         }
         if (upload::not_empty($upload) and upload::valid($upload)) {
             $seed = Arr::get($_POST, '__SEED__', md5(Request::current()->uri() . time()));
             $tmp_name = $seed . '-' . md5_file($upload['tmp_name']);
             if (upload::save($upload, $tmp_name, Kohana::$cache_dir) !== FALSE) {
                 $timestamp = 24 * 60 * 60;
                 $cache->set($tmp_name, array('upload' => $upload, 'timestamp' => $timestamp), $timestamp);
                 $tmp_old_file = Arr::get($_POST, $key . $surfix);
                 if (!empty($tmp_old_file) and file_exists(Kohana::$cache_dir . DIRECTORY_SEPARATOR . $tmp_old_file)) {
                     try {
                         unlink(Kohana::$cache_dir . DIRECTORY_SEPARATOR . $tmp_old_file);
                         $cache->delete($tmp_old_file);
                     } catch (Exception $e) {
                     }
                 }
                 $this->parent->model->set($key, $tmp_name);
             }
         }
     }
 }
コード例 #30
0
ファイル: backgrounds.php プロジェクト: natgeo/kids-myshot
 public function action_save()
 {
     $data = (object) filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
     $background = ORM::factory("background", $data->id);
     if (!$background->loaded()) {
         $background = ORM::factory("background");
     }
     $background->color = $data->color;
     if ($_FILES["image"]["error"] == 0) {
         $filename = upload::save($_FILES['image'], $_FILES['image']['name'], Kohana::config('myshot.relativeBase'));
         $thumbName = substr($_FILES['image']['name'], 0, strlen($_FILES['image']['name']) - 4) . '-thumb' . substr($_FILES['image']['name'], -4);
         $localThumb = Kohana::config('myshot.relativeBase') . $thumbName;
         Image::factory($filename)->resize(100, 91, Image::WIDTH)->save($localThumb);
         Library_Akamai::factory()->addToDir($filename, "backgrounds")->addToDir($localThumb, "backgrounds");
         $background->path = "backgrounds/" . $_FILES['image']['name'];
         $background->thumb = "backgrounds/" . $thumbName;
         unlink($filename);
         unlink($localThumb);
     }
     $background->save();
     Helper_Background::renderCSS();
     $this->request->redirect("admin/backgrounds");
 }