Table of Contents
Usage analysis of CI framework file upload class and image processing class, ci file upload
Home Backend Development PHP Tutorial Usage analysis of CI framework file upload class and image processing class, ci file upload_PHP tutorial

Usage analysis of CI framework file upload class and image processing class, ci file upload_PHP tutorial

Jul 12, 2016 am 08:52 AM
ci framework Image Processing File Upload

Usage analysis of CI framework file upload class and image processing class, ci file upload

This article describes the usage of CI framework file upload class and image processing class with examples. Share it with everyone for your reference, the details are as follows:

//列表页banner图片
public function edit_list_page_banner($category_id=""){
  $category_id= empty($category_id)?$_POST["category_id"]:$category_id;
  //上传图片
  if(isset($_POST["key"]) && $_POST["key"] == "upload"){
   /*
   1.set_upload_path
   */
   $config['upload_path']="./upload/source/".date("Y/m/d");//文件上传目录
   if(!file_exists("./upload/source/".date("Y/m/d"))){
    mkdir("./upload/source/".date("Y/m/d"),0777,true);//原图路径
   }
   if(!file_exists("./upload/big_thumb/".date("Y/m/d"))){
    mkdir("./upload/big_thumb/".date("Y/m/d"),0777,true);//大缩略图路径
   }
   if(!file_exists("./upload/small_thumb/".date("Y/m/d"))){
    mkdir("./upload/small_thumb/".date("Y/m/d"),0777,true);//小缩略图路径
   }
   $config['allowed_types']="gif|jpg|png|txt";//文件类型
   $config['max_size']="20000";//最大上传大小
   $this->load->library("upload",$config);
   if($this->upload->do_upload('userfile'))//表单中name="userfile"
   {
    //上传成功之后,生成两张缩略图
    $data=$this->upload->data();//返回上传图片的信息
    $this->load->library("image_lib");//载入图像处理类库
    //第一种方式:大缩略图的配置参数
    /*
    $config_big_thumb['image_library'] = 'gd2';//gd2图库
    $config_big_thumb['source_image'] = $data['full_path'];//原图
    $config_big_thumb['new_image'] = "./upload/big_thumb/".date("Y/m/d")."/".$data['file_name'];//大缩略图
    $config_big_thumb['create_thumb'] = true;//是否创建缩略图
    $config_big_thumb['maintain_ratio'] = true;
    $config_big_thumb['width'] = 300;//缩略图宽度
    $config_big_thumb['height'] = 300;//缩略图的高度
    $config_big_thumb['thumb_marker']="_300_300";//缩略图名字后加上 "_300_300",可以代表是一个300*300的缩略图
    */
    //第二种:大缩略图的配置参数
    /*
    $config_big_thumb=array(
     'image_library' => 'gd2',//gd2图库
     'source_image' => $data['full_path'],//原图
     'new_image' => "./upload/big_thumb/".date("Y/m/d")."/".$data['file_name'],//大缩略图
     'create_thumb' => true,//是否创建缩略图
     'maintain_ratio' => true,
     'width' => 300,//缩略图宽度
     'height' => 300,//缩略图的高度
     'thumb_marker'=>"_300_300"//缩略图名字后加上 "_300_300",可以代表是一个300*300的缩略图
    );
    */
    //第三种方式:将部分配置信息放到了config.php文件中
    $config_big_thumb=$this->config->item("config_big_thumb");
    $config_big_thumb['source_image']=$data['full_path'];
    $config_big_thumb['new_image']="./upload/big_thumb/".date("Y/m/d")."/".$data['file_name'];
    //小缩略图的配置参数
    /*
    $config_small_thumb['image_library'] = 'gd2';//gd2图库
    $config_small_thumb['source_image'] = $data['full_path'];//原图
    $config_small_thumb['new_image'] = "./upload/small_thumb/".date("Y/m/d")."/".$data['file_name'];//大缩略图
    $config_small_thumb['create_thumb'] = true;//是否创建缩略图
    $config_small_thumb['maintain_ratio'] = true;
    $config_small_thumb['width'] = 100;//缩略图宽度
    $config_small_thumb['height'] = 100;//缩略图的高度
    $config_small_thumb['thumb_marker']="_100_100";//缩略图名字后加上 "_100_100",可以代表是一个100*100的缩略图
    */
    //小缩略图的配置参数
    $config_small_thumb=array(
     'image_library' => 'gd2',//gd2图库
     'source_image' => $data['full_path'],//原图
     'new_image' => "./upload/small_thumb/".date("Y/m/d")."/".$data['file_name'],//大缩略图
     'create_thumb' => true,//是否创建缩略图
     'maintain_ratio' => true,
     'width' => 100,//缩略图宽度
     'height' => 100,//缩略图的高度
     'thumb_marker'=>"_100_100"//缩略图名字后加上 "_300_300",可以代表是一个300*300的缩略图
    );
    //$this->load->library("image_lib",$config_thumb);
    $this->image_lib->initialize($config_big_thumb);
    $this->image_lib->resize();//生成big缩略图
    $this->image_lib->initialize($config_small_thumb);
    $this->image_lib->resize();//生成small缩略图
    //插入数据库
    $data_array = array(
     'category_id' => $category_id,
     'pic_url' => "./upload/source/".date("Y/m/d")."/".$data['file_name'],
     'addtime' => time(),
     'is_stop' => 1,
     'sort'=>0,
     'gender' => $_POST["gender"],
     'link_url'=>$_POST["link_url"],
     'user_id' => intval($this->cur_user ['user_id'])
    );
    $this->category_model->add_category_banner($data_array);
   }
  }
  $con_arr[] = " category_id= '{$category_id}'";
  if ($gender=='' ) {
   $gender=0;
  }
  $con_arr[] = " gender= '{$gender}'";
  $condition = implode( ' and ', $con_arr);
  $banner_list = $this->category_model->get_banner_all($condition);
  $this->tp->assign('banner_list', $banner_list);
  $this->tp->assign('base_url', base_url());
  $this->tp->assign('gender', $gender);
  $this->tp->assign('category_id', $category_id);
  $this->tp->display("category/edit_list_page_banner.php");
}

Copy after login

Configuration items related to thumbnails in the config.php file:

//大缩略图的配置参数
$config_big_thumb=array(
 'image_library' => 'gd2',//gd2图库
 'create_thumb' => true,//是否创建缩略图
 'maintain_ratio' => true,
 'width' => 300,//缩略图宽度
 'height' => 300,//缩略图的高度
 'thumb_marker'=>"_300_300"//缩略图名字后加上 "_300_300",可以代表是一个300*300的缩略图
);

Copy after login

Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php excellent development framework summary", "ThinkPHP introductory tutorial", "Summary of Common Methods in ThinkPHP", "Introduction Tutorial on Zend FrameWork Framework", "Introduction Tutorial on PHP Object-Oriented Programming", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127857.htmlTechArticleCI framework file upload class and image processing class usage analysis, ci file upload This article describes the CI framework file upload class with examples and image processing usage. Share it with everyone for your reference, specifically...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How is Wasserstein distance used in image processing tasks? How is Wasserstein distance used in image processing tasks? Jan 23, 2024 am 10:39 AM

Wasserstein distance, also known as EarthMover's Distance (EMD), is a metric used to measure the difference between two probability distributions. Compared with traditional KL divergence or JS divergence, Wasserstein distance takes into account the structural information between distributions and therefore exhibits better performance in many image processing tasks. By calculating the minimum transportation cost between two distributions, Wasserstein distance is able to measure the minimum amount of work required to transform one distribution into another. This metric is able to capture the geometric differences between distributions, thereby playing an important role in tasks such as image generation and style transfer. Therefore, the Wasserstein distance becomes the concept

In-depth analysis of the working principles and characteristics of the Vision Transformer (VIT) model In-depth analysis of the working principles and characteristics of the Vision Transformer (VIT) model Jan 23, 2024 am 08:30 AM

VisionTransformer (VIT) is a Transformer-based image classification model proposed by Google. Different from traditional CNN models, VIT represents images as sequences and learns the image structure by predicting the class label of the image. To achieve this, VIT divides the input image into multiple patches and concatenates the pixels in each patch through channels and then performs linear projection to achieve the desired input dimensions. Finally, each patch is flattened into a single vector, forming the input sequence. Through Transformer's self-attention mechanism, VIT is able to capture the relationship between different patches and perform effective feature extraction and classification prediction. This serialized image representation is

How to use Laravel to implement file upload and download functions How to use Laravel to implement file upload and download functions Nov 02, 2023 pm 04:36 PM

How to use Laravel to implement file upload and download functions Laravel is a popular PHP Web framework that provides a wealth of functions and tools to make developing Web applications easier and more efficient. One of the commonly used functions is file upload and download. This article will introduce how to use Laravel to implement file upload and download functions, and provide specific code examples. File upload File upload refers to uploading local files to the server for storage. In Laravel we can use file upload

How to use AI technology to restore old photos (with examples and code analysis) How to use AI technology to restore old photos (with examples and code analysis) Jan 24, 2024 pm 09:57 PM

Old photo restoration is a method of using artificial intelligence technology to repair, enhance and improve old photos. Using computer vision and machine learning algorithms, the technology can automatically identify and repair damage and flaws in old photos, making them look clearer, more natural and more realistic. The technical principles of old photo restoration mainly include the following aspects: 1. Image denoising and enhancement. When restoring old photos, they need to be denoised and enhanced first. Image processing algorithms and filters, such as mean filtering, Gaussian filtering, bilateral filtering, etc., can be used to solve noise and color spots problems, thereby improving the quality of photos. 2. Image restoration and repair In old photos, there may be some defects and damage, such as scratches, cracks, fading, etc. These problems can be solved by image restoration and repair algorithms

Implement file upload and download in Workerman documents Implement file upload and download in Workerman documents Nov 08, 2023 pm 06:02 PM

To implement file upload and download in Workerman documents, specific code examples are required. Introduction: Workerman is a high-performance PHP asynchronous network communication framework that is simple, efficient, and easy to use. In actual development, file uploading and downloading are common functional requirements. This article will introduce how to use the Workerman framework to implement file uploading and downloading, and give specific code examples. 1. File upload: File upload refers to the operation of transferring files on the local computer to the server. The following is used

How to use gRPC to implement file upload in Golang? How to use gRPC to implement file upload in Golang? Jun 03, 2024 pm 04:54 PM

How to implement file upload using gRPC? Create supporting service definitions, including request and response messages. On the client, the file to be uploaded is opened and split into chunks, then streamed to the server via a gRPC stream. On the server side, file chunks are received and stored into a file. The server sends a response after the file upload is completed to indicate whether the upload was successful.

Application of AI technology in image super-resolution reconstruction Application of AI technology in image super-resolution reconstruction Jan 23, 2024 am 08:06 AM

Super-resolution image reconstruction is the process of generating high-resolution images from low-resolution images using deep learning techniques, such as convolutional neural networks (CNN) and generative adversarial networks (GAN). The goal of this method is to improve the quality and detail of images by converting low-resolution images into high-resolution images. This technology has wide applications in many fields, such as medical imaging, surveillance cameras, satellite images, etc. Through super-resolution image reconstruction, we can obtain clearer and more detailed images, which helps to more accurately analyze and identify targets and features in images. Reconstruction methods Super-resolution image reconstruction methods can generally be divided into two categories: interpolation-based methods and deep learning-based methods. 1) Interpolation-based method Super-resolution image reconstruction based on interpolation

Scale Invariant Features (SIFT) algorithm Scale Invariant Features (SIFT) algorithm Jan 22, 2024 pm 05:09 PM

The Scale Invariant Feature Transform (SIFT) algorithm is a feature extraction algorithm used in the fields of image processing and computer vision. This algorithm was proposed in 1999 to improve object recognition and matching performance in computer vision systems. The SIFT algorithm is robust and accurate and is widely used in image recognition, three-dimensional reconstruction, target detection, video tracking and other fields. It achieves scale invariance by detecting key points in multiple scale spaces and extracting local feature descriptors around the key points. The main steps of the SIFT algorithm include scale space construction, key point detection, key point positioning, direction assignment and feature descriptor generation. Through these steps, the SIFT algorithm can extract robust and unique features, thereby achieving efficient image processing.

See all articles