本文整理汇总了PHP中Upload::not_empty方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::not_empty方法的具体用法?PHP Upload::not_empty怎么用?PHP Upload::not_empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Upload
的用法示例。
在下文中一共展示了Upload::not_empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onUpdateDocument
public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
{
$files = Arr::get($_FILES, $this->name);
$remove_files = $new->get($this->name . '_remove');
if (!empty($remove_files)) {
ORM::factory('media')->delete_by_ids($remove_files);
}
if (empty($files)) {
return FALSE;
}
$old_files = $old->get($this->name);
$old_files = empty($old_files) ? array() : explode(',', $old_files);
$files = $this->_normalize_files($files);
foreach ($files as $file) {
if (!Upload::not_empty($file)) {
continue;
}
try {
$uploaded_file = ORM::factory('media')->set('module', $this->module_id())->upload($file, array('jpg', 'jpeg', 'gif', 'png'), $this->max_size);
if ($uploaded_file->loaded()) {
$old_files[] = $uploaded_file->id;
}
} catch (Exception $ex) {
continue;
}
}
$new->set($this->name, implode(',', $old_files));
return TRUE;
}
示例2: image
public static function image(array $file, $max_width = NULL, $max_height = NULL, $exact = FALSE)
{
if (Upload::not_empty($file)) {
try {
list($width, $height) = getimagesize($file['tmp_name']);
} catch (ErrorException $e) {
// Ignore read errors
}
if (empty($width) or empty($height)) {
return FALSE;
}
if (!$max_width) {
$max_width = $width;
}
if (!$max_height) {
$max_height = $height;
}
if ($exact) {
// Check if dimensions match exactly
return $width === $max_width and $height === $max_height;
} else {
// Check if size is within maximum dimensions
return $width <= $max_width and $height <= $max_height;
}
}
return FALSE;
}
示例3: _upload_image
public function _upload_image(Validate $array, $input)
{
if ($array->errors()) {
// Don't bother uploading
return;
}
// Get the image from the array
$image = $array[$input];
if (!Upload::valid($image) or !Upload::not_empty($image)) {
// No need to do anything right now
return;
}
if (Upload::valid($image) and Upload::type($image, $this->types)) {
$filename = strtolower(Text::random('alnum', 20)) . '.jpg';
if ($file = Upload::save($image, NULL, $this->directory)) {
Image::factory($file)->resize($this->width, $this->height, $this->resize)->save($this->directory . $filename);
// Update the image filename
$array[$input] = $filename;
// Delete the temporary file
unlink($file);
} else {
$array->error('image', 'failed');
}
} else {
$array->error('image', 'valid');
}
}
示例4: validate_uploaded_image
public static function validate_uploaded_image($image)
{
if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
return FALSE;
}
return TRUE;
}
示例5: action_image
public function action_image()
{
if (Core::post('photo_delete') and Auth::instance()->get_user()->delete_image() == TRUE) {
Alert::set(Alert::SUCCESS, __('Photo deleted.'));
$this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
}
// end of photo delete
//get image
$image = $_FILES['profile_image'];
//file post
if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
if (Upload::not_empty($image) && !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Is not valid format, please use one of this formats "jpg, jpeg, png"'));
$this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
}
if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Is not of valid size. Size is limited on ' . core::config('general.max_image_size') . 'MB per image'));
$this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
}
Alert::set(Alert::ALERT, $image['name'] . ' ' . __('Image is not valid. Please try again.'));
$this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
} else {
if ($image != NULL) {
$user = Auth::instance()->get_user();
// saving/uploadng zip file to dir.
$root = DOCROOT . 'images/users/';
//root folder
$image_name = $user->id_user . '.png';
$width = core::config('image.width');
// @TODO dynamic !?
$height = core::config('image.height');
// @TODO dynamic !?
$image_quality = core::config('image.quality');
// if folder does not exist, try to make it
if (!is_dir($root) and !@mkdir($root, 0775, TRUE)) {
// mkdir not successful ?
Alert::set(Alert::ERROR, __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.'));
return FALSE;
// exit function
}
// save file to root folder, file, name, dir
if ($file = Upload::save($image, $image_name, $root)) {
// resize uploaded image
Image::factory($file)->orientate()->resize($width, $height, Image::AUTO)->save($root . $image_name, $image_quality);
// update category info
$user->has_image = 1;
$user->last_modified = Date::unix2mysql();
$user->save();
Alert::set(Alert::SUCCESS, $image['name'] . ' ' . __('Image is uploaded.'));
} else {
Alert::set(Alert::ERROR, $image['name'] . ' ' . __('Icon file could not been saved.'));
}
$this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
}
}
}
示例6: get_val
public static function get_val(array $array)
{
$val = $array['val'];
if (is_array($val)) {
if (!Arr::get($val, 'custom') and !Upload::not_empty($val)) {
$val = NULL;
}
}
return $val ? $val : NULL;
}
示例7: does_file_exist
public function does_file_exist($file_path)
{
if (is_file($file_path)) {
return TRUE;
} elseif (isset($_FILES[$this->key])) {
return Upload::not_empty($_FILES[$this->key]);
} else {
return FALSE;
}
}
示例8: not_nude_image
/**
* Image nudity detector based on flesh color quantity.
*
* @param array $file uploaded file data
* @param string $threshold Threshold of flesh color in image to consider in pornographic. See page 302
* @return boolean
*/
public static function not_nude_image(array $file, $threshold = 0.5)
{
if (Upload::not_empty($file)) {
$image = Image::factory($file['tmp_name']);
if ($image->is_nude_image($threshold)) {
return FALSE;
}
}
return TRUE;
}
示例9: action_create
/**
* CRUD controller: CREATE
*/
public function action_create()
{
$this->auto_render = FALSE;
$this->template = View::factory('js');
if (!isset($_FILES['image'])) {
$this->template->content = json_encode('KO');
return;
}
$image = $_FILES['image'];
if (core::config('image.aws_s3_active')) {
require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
$s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
}
if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
if (Upload::not_empty($image) and !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats'))));
return;
}
if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size'))));
return;
}
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
return;
} elseif ($image != NULL) {
// saving/uploading img file to dir.
$path = 'images/cms/';
$root = DOCROOT . $path;
//root folder
$image_name = URL::title(pathinfo($image['name'], PATHINFO_FILENAME));
$image_name = Text::limit_chars(URL::title(pathinfo($image['name'], PATHINFO_FILENAME)), 200);
$image_name = time() . '.' . $image_name;
// if folder does not exist, try to make it
if (!file_exists($root) and !@mkdir($root, 0775, true)) {
// mkdir not successful ?
$this->template->content = json_encode(array('msg' => __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.')));
return;
// exit function
}
// save file to root folder, file, name, dir
if ($file = Upload::save($image, $image_name, $root)) {
// put image to Amazon S3
if (core::config('image.aws_s3_active')) {
$s3->putObject($s3->inputFile($file), core::config('image.aws_s3_bucket'), $path . $image_name, S3::ACL_PUBLIC_READ);
}
$this->template->content = json_encode(array('link' => Core::config('general.base_url') . $path . $image_name));
return;
} else {
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image file could not been saved.')));
return;
}
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
}
}
示例10: post_images
public function post_images()
{
$json = array();
$file = $_FILES['file'];
$module = $this->param('module', 'default');
if (!Upload::not_empty($file)) {
$this->json = json_encode($json);
return;
}
$image = ORM::factory('media')->set('module', $module)->upload($file, array('jpg', 'jpeg', 'gif', 'png'));
$json = array('id' => $image->id, 'thumb' => Image::cache($image->filename, 100, 100, Image::INVERSE), 'image' => PUBLIC_URL . $image->filename, 'title' => (string) $image->description, 'folder' => $image->module);
$this->response($json);
}
示例11: _save_image
protected function _save_image($image)
{
if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
return FALSE;
}
$directory = DOCROOT . '/public/media/image_product/';
if ($file = Upload::save($image, NULL, $directory)) {
$filename = strtolower(Text::random('alnum', 20)) . '.jpg';
Image::factory($file)->resize(500, 500, Image::AUTO)->save($directory . $filename);
// Delete the temporary file
unlink($file);
return $filename;
}
return FALSE;
}
示例12: save_image
/**
* @return bool|string
*/
private function save_image($image)
{
if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
return FALSE;
}
$directory = DOCROOT . $this->prefix;
if ($file = Upload::save($image, NULL, $directory)) {
// Save the image.
Image::factory($file)->resize($this->width(), $this->height())->save($directory . $this->_filename());
// Delete the temporary file
unlink($file);
return TRUE;
}
return FALSE;
}
示例13: action_add
public function action_add()
{
$user_id = $this->user->id;
if (empty($user_id)) {
$this->redirect('/');
}
$article = new Model_Article();
$article->title = Arr::get($_POST, 'title');
$article->description = Arr::get($_POST, 'description');
$article->text = Arr::get($_POST, 'text');
$cover = Arr::get($_FILES, 'cover');
$errors = FALSE;
$table_values = array();
if ($article->title != '') {
$table_values['title'] = array('value' => $article->title);
} else {
$errors = TRUE;
}
if ($article->description != '') {
$table_values['description'] = array('value' => $article->description);
} else {
$errors = TRUE;
}
if ($article->text != '') {
$table_values['text'] = array('value' => $article->text);
} else {
$errors = TRUE;
}
if (!Upload::valid($cover) or !Upload::not_empty($cover) or !Upload::type($cover, array('jpg', 'jpeg', 'png')) or !Upload::size($cover, '10M')) {
$table_values['cover'] = TRUE;
$errors = TRUE;
}
if ($errors) {
// $this->view["editor"] = View::factory('templates/articles/editor', array("storedNodes" => $table_values['text']['value']));
$content = View::factory('templates/articles/new', $this->view);
$this->template->content = View::factory("templates/articles/wrapper", array("active" => "newArticle", "content" => $content));
return false;
}
// getting new name for cover
$article->cover = $this->methods->save_cover($cover);
$article->user_id = $user_id;
$article->is_published = true;
// FIXME изменить, когда будет доступны режимы публикации
$article->insert();
// redirect to new article
$this->redirect('/article/' . $article->id);
}
示例14: action_upload_files
public function action_upload_files()
{
$files = array();
if (isset($_FILES)) {
foreach ($_FILES as $name => $file) {
if (Upload::not_empty($file)) {
$filename = uniqid() . '_' . $file['name'];
$filename = preg_replace('/\\s+/u', '_', $filename);
$dir = 'public' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'page_media';
create_dir($dir);
Upload::save($file, $filename, DOCROOT . $dir);
$files[] = array('url' => URL::site($dir . '/' . $filename), 'file' => $file, 'dir' => $dir, 'filename' => $filename);
}
}
}
$this->response->json(array('files' => $files));
}
示例15: action_upload
public function action_upload()
{
$field = 'Filedata';
if (($value = Arr::get($_FILES, $field, FALSE)) === FALSE) {
$this->request->response = 'error';
return;
}
if (!Upload::not_empty($value) or !Upload::valid($value)) {
$this->request->response = 'error';
return;
}
if ($tmp_name = Torn_Uploader::upload_to_cache($value, $field)) {
$this->request->response = 'done;' . $tmp_name;
} else {
$this->request->response = 'error';
}
}