【问题标题】:I am facing issue in moving file into my desired folder我在将文件移动到所需文件夹时遇到问题
【发布时间】:2019-10-02 05:41:26
【问题描述】:

我需要将我的文件移动到我想要的位置,但我的文件没有移动到文件夹中,所以请帮助我。

   Here is the code of my controller "Sms_Controller".       

    $pic_file1 = $this->input->post('pic_file');
    $pic_file1 = str_replace( "\\", '/', $pic_file1);
    $filename = basename($pic_file1);



        $config['upload_path']          = BASEPATH. '../assets/uploads/';
        $config['allowed_types']        = 'gif|jpg|png';
        $config['max_size']             = 1000;

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('pic_file')){
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('reg_dsa', $error);
        }else{

            //file is uploaded successfully
            //now get the file uploaded data 
            $upload_data = $this->upload->data();

            //get the uploaded file name


        }

【问题讨论】:

  • 上传后要移动还是直接放到上传文件夹中?

标签: php html css ajax codeigniter


【解决方案1】:

以下是从网站根目录上传文件到所需文件夹和根目录中的uploadFolder的通用代码。

/*------------------------ File Upload --------------------------- */


        $config['upload_path'] = './uploadFolder/';
        $config['allowed_types'] = 'pdf|jpg|jpeg|png';
        $this->load->library('upload', $config);
        $filename = "";
        if (!$this->upload->do_upload('filename')) {
            //$this->session->set_flashdata('error_msg', $this->upload->display_errors());
        } else {
            $data1 = array('upload_data' => $this->upload->data());
            $filename = "" . $data1["upload_data"]["file_name"];
        }

$filename is the Filename required to store in the database

【讨论】:

  • 为什么要加载上传库两次
  • 对不起,写错了,我会编辑帖子。感谢您的认可
【解决方案2】:

请替换此代码

                $config['upload_path']          = './assets/uploads/';
                $config['allowed_types']        = 'gif|jpg|png';
                $config['max_size']             = 100;
                $config['max_width']            = 1024;
                $config['max_height']           = 768;

                $this->load->library('upload', $config);

                if ( ! $this->upload->do_upload('pic_file'))
                {
                        $error = array('error' => $this->upload->display_errors());
                        print_r($error);

                }
                else
                {
                        $data = array('upload_data' => $this->upload->data());
                        print_r($data);

                }
                die; 

【讨论】:

    猜你喜欢
    • 2022-06-10
    • 1970-01-01
    • 2017-05-04
    • 2022-01-09
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多