CI框架3.x 之文件上传与生成缩略图

摘要:
1、 效果图二。代码˂?

一、效果图

CI框架3.x 之文件上传与生成缩略图第1张

 二、代码

<?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)));
        }
    }
}

免责声明:文章转载自《CI框架3.x 之文件上传与生成缩略图》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇性能调优之top命令详解spring相关的问题和原因分析下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

一个体验好的Windows 任务栏缩略图开发心得

本文来自网易云社区 作者:孙有军 前言: 对于一个追求极致体验的软件来说,利用好系统的每一点优秀的特性,将会大大提高软件的品质。 Windows vista以来任务栏缩略图,及Win + TAB的程序切换预览图的定制也是对软件体验的一个巨大提升,这里我对云音乐中使用到的任务栏缩率图显示专辑封面,并且控制播放歌曲操作的开发做下简单的分享。 缩...

iOS 开发之照片框架详解之二 —— PhotoKit 详解(下)

本文链接:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-three.html 这里接着前文《iOS 开发之照片框架详解之二 —— PhotoKit 详解(上)》,主要是干货环节,列举了如何基于 PhotoKit 与 AlAssetLibrary 封装出通用的方法...

照片上传(缩略图实现)

1.获取所有的提交到服务器的文件集合 HttpFileCollection fileColl= Request.Files; 2.取得一个文件(这里是一张照片)     HttpPostedFile pic = fileColl[0]; 3.判断文件是否为空     1.获取服务器存放图片的物理路径(Server.MapPath)        strin...

用google在线播放器播放MP3和FLV

播放MP3文件 <embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=MP3文件URL" width="400" height="27" allowscriptacce...

微信分享网页的缩略图

微信公众平台很多时候都需要跳转到网页展示和实现一些功能,而这些网页也是可以被用户分享到朋友圈或发送给朋友的。分享和发送的时候一般都是一个缩略图,一个标题和一个介绍。可是有时候分享的网页缩略图部分是空白的,虽然网页里是包含了图片的,所以就需要研究一下这个缩略图到底怎么。...

windows xp查看缩略图时有缩略图没有文件名

windows xp查看缩略图时有缩略图没有文件名 当我们在资源管理器中以缩略图形式显示图形文件的时候,所有的图形文件都会以缩小的形式把自己的内容显示出来,不过同时还显示了文件名。如果你想在显示缩略图的时候隐藏文件名,那只要在查看菜单下切换到缩略图模式的同时按下Shift键就可以了,反过来操作就是可以恢复显示文件名...