douhuan1937 2012-12-24 05:39 采纳率: 0%
浏览 18

我不能在post数组codeigniter中使用文件输入名称

I was trying to upload several files together with CI framework. what I want is upload files to different folders. Therefore, I tried check file input element's name and set fill path.

Here is the code to get clear idea about my problem.

$config['allowed_types'] = 'jpg|doc|pdf|docx';
        //$config['max_size']   = '100';
        //$config['max_width']  = '1024';
        //$config['max_height']  = '768';
            if($this->input->post('bankbook_attachment')){
                echo 'bank'.$this->input->post('bankbook_attachment');
                $config['upload_path'] = './uploads/bank/';

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

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

                        echo 'error'.print_r($error);
                }
                else
                {
                     //   $data = array('upload_data' => $this->upload->data());
                       // print_r($data);
                        $datame=$this->upload->data();
                        $fillnamebank= $datame['file_name'];
                        echo 'fillname is'.$fillnamebank;
                      // $this->load->view('upload_success', $data);
                }


            }
            if($this->input->post('emp_nic_attachment')){
                $config['upload_path'] = './uploads/nic/';
                $fillselect='emp_nic_attachment';
                $this->load->library('upload', $config);

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

                        echo 'error'.print_r($error);
                }
                else
                {
                     //   $data = array('upload_data' => $this->upload->data());
                       // print_r($data);
                        $datame=$this->upload->data();
                        $fillnamenic= $datame['file_name'];
                        echo 'fillname is'.$fillnamenic;
                      // $this->load->view('upload_success', $data);
                }
            }

but when I run the code I notice that it doesn't validate if conditions, it leaves them. In CI examples I have notice that they don't use post array to get the name but directly hard code. But which is impossible in my application.

How to solve this. I think simply problem is in this line $this->input->post('emp_nic_attachment')

  • 写回答

2条回答 默认 最新

  • doudeng5764 2012-12-24 06:24
    关注

    Since you are updating the upload directory in the $config, i don't think you have to check the 'fill name'. The below code would be enough

    $config['upload_path'] = './uploads/bank/';
    $this->load->library('upload', $config);
    
    if ( ! $this->upload->do_upload('bankbook_attachment'))
    {
        $error = array('error' => $this->upload->display_errors());
        echo 'error'.print_r($error);
    }
    else
    {
        $datame=$this->upload->data();
        $fillnamebank= $datame['file_name'];
        echo 'fillname is'.$fillnamebank;
    }
    
    $config['upload_path'] = './uploads/nic/';
    $this->load->library('upload', $config);
    if ( ! $this->upload->do_upload('emp_nic_attachment'))
    {
        $error = array('error' => $this->upload->display_errors());
        echo 'error'.print_r($error);
    }
    else
    {
        $datame=$this->upload->data();
        $fillnamenic= $datame['file_name'];
        echo 'fillname is'.$fillnamenic;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计