当前位置: 首页>>代码示例>>PHP>>正文


PHP CI::upload方法代码示例

本文整理汇总了PHP中CI::upload方法的典型用法代码示例。如果您正苦于以下问题:PHP CI::upload方法的具体用法?PHP CI::upload怎么用?PHP CI::upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CI的用法示例。


在下文中一共展示了CI::upload方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: form

 public function form($id = 0)
 {
     \CI::load()->helper('form_helper');
     \CI::load()->library('form_validation');
     \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>');
     $data = ['id' => '', 'filename' => '', 'max_downloads' => '', 'title' => '', 'size' => ''];
     if ($id) {
         $data = array_merge($data, (array) \CI::DigitalProducts()->getFileInfo($id));
     }
     $data['page_title'] = lang('digital_products_form');
     \CI::form_validation()->set_rules('max_downloads', 'lang:max_downloads', 'numeric');
     \CI::form_validation()->set_rules('title', 'lang:title', 'trim|required');
     if (\CI::form_validation()->run() == FALSE) {
         $this->view('digital_product_form', $data);
     } else {
         if ($id == 0) {
             $data['file_name'] = false;
             $data['error'] = false;
             $config['allowed_types'] = '*';
             $config['upload_path'] = 'uploads/digital_products';
             //config_item('digital_products_path');
             $config['remove_spaces'] = true;
             \CI::load()->library('upload', $config);
             if (\CI::upload()->do_upload()) {
                 $upload_data = \CI::upload()->data();
             } else {
                 $data['error'] = \CI::upload()->display_errors();
                 $this->view('digital_product_form', $data);
                 return;
             }
             $save['filename'] = $upload_data['file_name'];
             $save['size'] = $upload_data['file_size'];
         } else {
             $save['id'] = $id;
         }
         $save['max_downloads'] = \CI::input()->post('max_downloads');
         $save['title'] = \CI::input()->post('title');
         \CI::DigitalProducts()->save($save);
         redirect('admin/digital_products');
     }
 }
开发者ID:lekhangyahoo,项目名称:gonline,代码行数:41,代码来源:AdminDigitalProducts.php

示例2: upload_image

 public function upload_image()
 {
     $config['upload_path'] = 'uploads/wysiwyg/images';
     $config['allowed_types'] = 'gif|jpg|png';
     \CI::load()->library('upload', $config);
     if (!\CI::upload()->do_upload('file')) {
         $error = array('error' => \CI::upload()->display_errors('', ''));
         echo stripslashes(json_encode($error));
     } else {
         $data = \CI::upload()->data();
         //upload successful generate a thumbnail
         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/wysiwyg/images/' . $data['file_name'];
         $config['new_image'] = 'uploads/wysiwyg/thumbnails/' . $data['file_name'];
         $config['create_thumb'] = FALSE;
         $config['maintain_ratio'] = TRUE;
         $config['width'] = 75;
         $config['height'] = 50;
         \CI::load()->library('image_lib', $config);
         \CI::image_lib()->resize();
         $data = array('filelink' => base_url('uploads/wysiwyg/images/' . $data['file_name']), 'filename' => $data['file_name']);
         echo stripslashes(json_encode($data));
     }
 }
开发者ID:lekhangyahoo,项目名称:gonline,代码行数:24,代码来源:AdminWysiwyg.php

示例3: product_image_upload

 public function product_image_upload()
 {
     $data['file_name'] = false;
     $data['error'] = false;
     $config['allowed_types'] = 'gif|jpg|png';
     //$config['max_size']   = config_item('size_limit');
     $config['upload_path'] = 'uploads/images/full';
     $config['encrypt_name'] = true;
     $config['remove_spaces'] = true;
     \CI::load()->library('upload', $config);
     if (\CI::upload()->do_upload()) {
         $upload_data = \CI::upload()->data();
         \CI::load()->library('image_lib');
         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/images/full/' . $upload_data['file_name'];
         $config['new_image'] = 'uploads/images/medium/' . $upload_data['file_name'];
         $config['maintain_ratio'] = TRUE;
         $config['width'] = 600;
         $config['height'] = 500;
         \CI::image_lib()->initialize($config);
         \CI::image_lib()->resize();
         \CI::image_lib()->clear();
         //small image
         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/images/medium/' . $upload_data['file_name'];
         $config['new_image'] = 'uploads/images/small/' . $upload_data['file_name'];
         $config['maintain_ratio'] = TRUE;
         $config['width'] = 235;
         $config['height'] = 235;
         \CI::image_lib()->initialize($config);
         \CI::image_lib()->resize();
         \CI::image_lib()->clear();
         //cropped thumbnail
         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/images/small/' . $upload_data['file_name'];
         $config['new_image'] = 'uploads/images/thumbnails/' . $upload_data['file_name'];
         $config['maintain_ratio'] = TRUE;
         $config['width'] = 150;
         $config['height'] = 150;
         \CI::image_lib()->initialize($config);
         \CI::image_lib()->resize();
         \CI::image_lib()->clear();
         $data['file_name'] = $upload_data['file_name'];
     }
     if (\CI::upload()->display_errors() != '') {
         $data['error'] = \CI::upload()->display_errors();
     }
     $this->partial('iframe/product_image_uploader', $data);
 }
开发者ID:vandona,项目名称:v3,代码行数:49,代码来源:AdminProducts.php

示例4: form

 function form($id = false)
 {
     $data['groups'] = \CI::Customers()->get_groups();
     $config['upload_path'] = 'uploads/images/full';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size'] = config_item('size_limit');
     $config['max_width'] = '1024';
     $config['max_height'] = '768';
     $config['encrypt_name'] = true;
     \CI::load()->library('upload', $config);
     $this->category_id = $id;
     \CI::load()->helper('form');
     \CI::load()->library('form_validation');
     \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>');
     $data['categories'] = \CI::Categories()->getCategoryOptionsMenu($id);
     $data['page_title'] = lang('category_form');
     //default values are empty if the customer is new
     $data['id'] = '';
     $data['name'] = '';
     $data['slug'] = '';
     $data['description'] = '';
     $data['excerpt'] = '';
     $data['sequence'] = '';
     $data['image'] = '';
     $data['seo_title'] = '';
     $data['meta'] = '';
     $data['parent_id'] = 0;
     $data['error'] = '';
     foreach ($data['groups'] as $group) {
         $data['enabled_' . $group->id] = '';
     }
     //create the photos array for later use
     $data['photos'] = [];
     if ($id) {
         $category = \CI::Categories()->find($id);
         //if the category does not exist, redirect them to the category list with an error
         if (!$category) {
             \CI::session()->set_flashdata('error', lang('error_not_found'));
             redirect('admin/categories');
         }
         //helps us with the slug generation
         $this->category_name = \CI::input()->post('slug', $category->slug);
         //set values to db values
         $data['id'] = $category->id;
         $data['name'] = $category->name;
         $data['slug'] = $category->slug;
         $data['description'] = $category->description;
         $data['excerpt'] = $category->excerpt;
         $data['sequence'] = $category->sequence;
         $data['parent_id'] = $category->parent_id;
         $data['image'] = $category->image;
         $data['seo_title'] = $category->seo_title;
         $data['meta'] = $category->meta;
         foreach ($data['groups'] as $group) {
             $data['enabled_' . $group->id] = $category->{'enabled_' . $group->id};
         }
     }
     \CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|max_length[64]');
     \CI::form_validation()->set_rules('slug', 'lang:slug', 'trim');
     \CI::form_validation()->set_rules('description', 'lang:description', 'trim');
     \CI::form_validation()->set_rules('excerpt', 'lang:excerpt', 'trim');
     \CI::form_validation()->set_rules('sequence', 'lang:sequence', 'trim|integer');
     \CI::form_validation()->set_rules('parent_id', 'parent_id', 'trim');
     \CI::form_validation()->set_rules('image', 'lang:image', 'trim');
     \CI::form_validation()->set_rules('seo_title', 'lang:seo_title', 'trim');
     \CI::form_validation()->set_rules('meta', 'lang:meta', 'trim');
     foreach ($data['groups'] as $group) {
         \CI::form_validation()->set_rules('enabled_' . $group->id, lang('enabled') . '(' . $group->name . ')', 'trim|numeric');
     }
     // validate the form
     if (\CI::form_validation()->run() == FALSE) {
         $this->view('category_form', $data);
     } else {
         $uploaded = \CI::upload()->do_upload('image');
         if ($id) {
             //delete the original file if another is uploaded
             if ($uploaded) {
                 if ($data['image'] != '') {
                     $file = [];
                     $file[] = 'uploads/images/full/' . $data['image'];
                     $file[] = 'uploads/images/medium/' . $data['image'];
                     $file[] = 'uploads/images/small/' . $data['image'];
                     $file[] = 'uploads/images/thumbnails/' . $data['image'];
                     foreach ($file as $f) {
                         //delete the existing file if needed
                         if (file_exists($f)) {
                             unlink($f);
                         }
                     }
                 }
             }
         }
         if (!$uploaded) {
             $data['error'] = \CI::upload()->display_errors();
             if ($_FILES['image']['error'] != 4) {
                 $data['error'] .= \CI::upload()->display_errors();
                 $this->view('category_form', $data);
                 return;
                 //end script here if there is an error
             }
//.........这里部分代码省略.........
开发者ID:buzkall,项目名称:GoCart3,代码行数:101,代码来源:AdminCategories.php

示例5: banner_form

 public function banner_form($banner_collection_id, $id = false)
 {
     $config['upload_path'] = 'uploads';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['encrypt_name'] = true;
     \CI::load()->library('upload', $config);
     \CI::load()->helper(array('form', 'date'));
     \CI::load()->library('form_validation');
     //set the default values
     $data = array('banner_id' => $id, 'banner_collection_id' => $banner_collection_id, 'name' => '', 'enable_date' => '', 'disable_date' => '', 'image' => '', 'link' => '', 'new_window' => false);
     if ($id) {
         $data = array_merge($data, (array) \CI::Banners()->banner($id));
         $data['new_window'] = (bool) $data['new_window'];
     }
     $data['page_title'] = lang('banner_form');
     \CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|full_decode');
     \CI::form_validation()->set_rules('enable_date', 'lang:enable_date', 'trim');
     \CI::form_validation()->set_rules('disable_date', 'lang:disable_date', 'trim');
     \CI::form_validation()->set_rules('image', 'lang:image', 'trim');
     \CI::form_validation()->set_rules('link', 'lang:link', 'trim');
     \CI::form_validation()->set_rules('new_window', 'lang:new_window', 'trim');
     if (\CI::form_validation()->run() == false) {
         $data['error'] = validation_errors();
         $this->view('banner_form', $data);
     } else {
         $uploaded = \CI::upload()->do_upload('image');
         $save['banner_collection_id'] = $banner_collection_id;
         $save['name'] = \CI::input()->post('name');
         $save['enable_date'] = \CI::input()->post('enable_date');
         $save['disable_date'] = \CI::input()->post('disable_date');
         $save['link'] = \CI::input()->post('link');
         $save['new_window'] = (bool) \CI::input()->post('new_window');
         if ($id) {
             $save['banner_id'] = $id;
             //delete the original file if another is uploaded
             if ($uploaded) {
                 if ($data['image'] != '') {
                     $file = 'uploads/' . $data['image'];
                     //delete the existing file if needed
                     if (file_exists($file)) {
                         unlink($file);
                     }
                 }
             }
         } else {
             if (!$uploaded) {
                 $data['error'] = \CI::upload()->display_errors();
                 $this->view('banner_form', $data);
                 return;
                 //end script here if there is an error
             }
         }
         if ($uploaded) {
             $image = \CI::upload()->data();
             $save['image'] = $image['file_name'];
         }
         \CI::Banners()->save_banner($save);
         \CI::session()->set_flashdata('message', lang('message_banner_saved'));
         redirect('admin/banners/banner_collection/' . $banner_collection_id);
     }
 }
开发者ID:lekhangyahoo,项目名称:gonline,代码行数:61,代码来源:Banners.php


注:本文中的CI::upload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。