简体   繁体   中英

How can I upload the filename and filepath of the image I uploaded inside “upload” folder using CodeIgniter?

This is my Controller.

 function upload_file() { 
                $config['upload_path']          = './upload/';
                $config['allowed_types']        = 'iso|dmg|zip|rar|doc|docx|xls|xlsx|ppt|pptx|csv|ods|odt|odp|pdf|rtf|sxc|sxi|txt|psd|exe|avi|mpeg|mp3|mp4|3gp|gif|jpg|jpeg|png';
                $config['max_size']             = 3072;
                $config['max_width']            = 1024;
                $config['max_height']           = 768;
                $this->upload->initialize($config);
                $this->load->library('upload', $config);

                if (!$this->upload->do_upload('userfile'))
                {
                        $error = array('error' => $this->upload->display_errors());
                        $this->load->view('header');
                        $this->load->view('file', $error);
                        $this->load->view('footer');
                }
                else
                {
                        $data = array('upload_data' => $this->upload->data()); 
                        $this->load->view('header');
                        $this->load->view('file', $data);
                        $this->load->view('footer');
                }
    }

How can I make the model? I want to upload the filename and the path of the uploaded image.

要显示图像,可以使用以下方法:

<img src="<?php echo base_url('upload/' . $image_name); ?>" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM