zoukankan      html  css  js  c++  java
  • CI框架3.x 之文件上传与生成缩略图

    一、效果图

     二、代码

    <?php
    /**
     * Created by PhpStorm.
     * User: 25754
     * Date: 2020/3/5
     * Time: 15:46
     */
    
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    class Upload extends CI_Controller
    {
        public function doUpload()
        {
            $width = $this->input->post("width");
            $height = $this->input->post("height");
            $config['upload_path'] = './upload/img/';
            $config['allowed_types'] = 'gif|jpg|png|jpeg';
            $config['max_size'] = 2 * 1024 * 1024;
            $config['max_width'] = 1024;
            $config['max_height'] = 768;
    
            $this->load->library('upload', $config);
    
            if (!$this->upload->do_upload('file')) {
                $error = array('error' => $this->upload->display_errors());
                die(json_encode(array("code" => 1, "error" => $error)));
            } else {
                $data = array('upload_data' => $this->upload->data());
                $config['image_library'] = 'gd2';
                $config['source_image'] = './upload/img/' . $data['upload_data']['file_name'];
                $config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = $width;
                $config['height'] = $height;
                $this->load->library('image_lib', $config);
                $this->image_lib->resize();
                $path = "/upload/img/" . $data['upload_data']['raw_name'] . '_thumb' . $data['upload_data']['file_ext'];
                die(json_encode(array("code" => 0, "path" => $path)));
            }
        }
    }
  • 相关阅读:
    MVC中使用AuthorizeAttribute做身份验证操作
    Entity Framework 5.0 Code First全面学习
    AngularJs学习教程
    安装完Oracle数据库,给scott账户解锁方法
    Signalr学习教程
    javascript学习教程【Qi Fei】
    并行开发
    MongoDB教程【一】
    统计学习概念
    自学Python的点滴
  • 原文地址:https://www.cnblogs.com/yang-2018/p/12433235.html
Copyright © 2011-2022 走看看