简体   繁体   English

如何使用CodeIgniter在“ upload”文件夹中上传图像的文件名和文件路径?

[英]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); ?>" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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