How to Upload Image files Using Codeigniter? [closed]

二次信任 提交于 2019-12-13 09:48:58

问题


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...

Thanks in advance..


回答1:


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

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                                      
        }  
    }
}

Then in your view

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


来源:https://stackoverflow.com/questions/15719477/how-to-upload-image-files-using-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!