Codeigniter-如何上传带有缩略图的原始图像? [英] Codeigniter - How to upload original image with thumbnail image?

查看:49
本文介绍了Codeigniter-如何上传带有缩略图的原始图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以在codeigniter中上传文件:

I have this code to file upload in codeigniter:

if(!empty($_FILES['userfile'])){
    $name_array = array();
    $count = count($_FILES['userfile']['size']);
    foreach($_FILES as $key => $value)
        for ($s=0; $s<=$count-1; $s++){
            $_FILES['userfile']['name'] = $value['name'][$s];
            $_FILES['userfile']['type'] = $value['type'][$s];
            $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
            $_FILES['userfile']['error'] = $value['error'][$s];
            $_FILES['userfile']['size'] = $value['size'][$s];
            $config['upload_path'] = './public/images/campaign-images/';
            $config['allowed_types'] = 'gif|jpg|jpeg|png|GIF|JPG|JPEG|PNG';
            $config['max_size'] = '10000';
            //$config['max_width'] = '1024';
            //$config['max_height'] = '768';
            $CI->load->library('upload', $config);
            $CI->upload->do_upload();
            $data = $CI->upload->data();
            $name_array[] = $data['file_name'];
        }
    return $name_array;
}

此代码与单个原始图像上传完美配合,但如何以缩略图(350 x 250),并且在其他文件夹中具有调整大小。

This code is working perfect with single original image upload but how to upload image as thumbnail image(350 x 250) with resize in different folder.

任何想法如何使用codeigniter库吗?

Any idea how to do with codeigniter library?

谢谢

推荐答案

首先存储原始图像,然后缩略图将上传
您只需要包括gd2库生成缩略图图像

First store the original image and afterwards thumbnail image will upload You just need to include gd2 library to generate the thumbnail image

            if(!empty($_FILES['userfile'])){
                $name_array = array();
                $count = count($_FILES['userfile']['size']);
                foreach($_FILES as $key => $value)
                    for ($s=0; $s<=$count-1; $s++)
                    {
                        //Original Image Upload - Start
                        $_FILES['userfile']['name'] = $value['name'][$s];
                        $_FILES['userfile']['type'] = $value['type'][$s];
                        $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
                        $_FILES['userfile']['error'] = $value['error'][$s];
                        $_FILES['userfile']['size'] = $value['size'][$s];
                        $config['upload_path'] = './public/images/campaign-images/';
                        $config['allowed_types'] = 'gif|jpg|jpeg|png|GIF|JPG|JPEG|PNG';
                        $config['max_size'] = '10000';
                        //$config['max_width'] = '1024';
                        //$config['max_height'] = '768';
                        $CI->load->library('upload', $config);
                        $CI->upload->do_upload();
                        $data = $CI->upload->data();
                        //Original Image Upload - End

                        //Thumbnail Image Upload - Start
                        $config['image_library'] = 'gd2';
                        $config['source_image'] = './public/images/campaign-images/'. $value['name'][$s];
                        $config['new_image'] = './public/images/campaign-images/thumbs/'.$value['name'][$s];
                        $config['width'] = 350;
                        $config['height'] = 250;

                        //load resize library
                        $this->load->library('image_lib', $config);
                        $this->image_lib->resize();
                        //Thumbnail Image Upload - End

                        $name_array[] = $data['file_name'];
                    }
                return $name_array;
            }

这篇关于Codeigniter-如何上传带有缩略图的原始图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆