如何使用Codeigniter上传图像文件? [英] How to Upload Image files Using Codeigniter?

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

问题描述

如何使用Codeigniter上传图像文件?
Codeigniter的上载类库

How to Upload Image files Using Codeigniter? Codeigniter's Upload class Library

不提供有关如何使用简单格式上传图像并将图像上传到根目录中存在的图像文件夹的提示...

gives no hint for how to upload a image using simple form and upload the image to it's images folder which is present in the root directory...

请先谢谢。。

推荐答案

这里是一个示例。希望这会对您有所帮助:)

Here is an example. Hope this would help you :)

在您的控制器中。可以说 upload.php

in your controller. lets say upload.php

public function upload() {
    if($this->input->post('upload')) {

        $config['upload_path'] = APPPATH . 'your upload folder name here/'; 
        $config['file_name'] = filename_here;
        $config['overwrite'] = TRUE;
        $config["allowed_types"] = 'jpg|jpeg|png|gif';
        $config["max_size"] = 1024;
        $config["max_width"] = 400;
        $config["max_height"] = 400;
        $this->load->library('upload', $config);

        if(!$this->upload->do_upload()) {               
            $this->data['error'] = $this->upload->display_errors();
        } else {
            //success                                      
        }  
    }
}

然后在您看来

<?php echo form_open_multipart('upload'); ?>    
<?php echo form_upload('userfile'); ?><br />
<?php echo form_submit('upload', 'Upload');?>    
<?php echo form_close(); ?>

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

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