dongmaobeng7145 2016-05-30 14:50
浏览 35
已采纳

PHP CodeIgniter:文件上传速度不够快,并且在没有文件的情况下继续进行

I have a submit file code that uploads an Excel file to my server and then uses it through the function.

When doing so:

    if ($this->upload->do_upload()){
        $data = array('upload_data' => $this->upload->data());

        $filename = $data['raw_name'];
        $fullfilename = $data['orig_name'];

        $inputFileName = FCPATH."files/automation/1/$filename.xlsx";
        $inputFileNameNew = FCPATH."files/automation/1/$filename-new.xlsx";

It gives me this output:

Error loading file ".xlsx": Could not open /var/www/html/tools/files/automation/1/.xlsx for reading! File does not exist.

Where I suspect it's because it hasn't found the file because it wasn't uploaded yet. Could be?

  • 写回答

1条回答 默认 最新

  • dtpw54085 2016-05-30 15:12
    关注

    if you want to upload a file in diferents folders by user or whatever you need to do this

    public function upload_f(){
        $config['upload_path']      = FCPATH . '/files/automation/' . $id . '/';
        $config['allowed_types']    = 'xls|xlsx';
    
        $this->load->library('upload', $config);
    
        if( ! $this->upload->do_upload()){
            $this->session->set_flashdata('upload-no', $this->upload->display_errors());
        }
        else{
            $this->_read_file(FCPATH . '/files/automation/' . $id . '/' . $this->upload->file_name);
        }
    }
    
    private funtion _read_file( $file ){
        $this->load->library('excel');
        $this->load->library('table');
    
        $file               = str_replace('//', '/', $file);
    
        $objPHPExcel = PHPExcel_IOFactory::load($file);
    
        $cell_collection    = $objPHPExcel->getActiveSheet()->getCellCollection();
        $lastRow            = $objPHPExcel->getActiveSheet()->getHighestRow();
    
        foreach ($cell_collection as $cell) {
            $column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
            $row    = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
            $data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
    
            if ($row == 1) {
                $header[$row][$column] = $data_value;
            } 
            else{
                $arr_data[$row][$column] = $data_value;
            }
        }
    
        $this->table->set_heading('ID', 'value1', 'value2');
    
        for($i = 2; $i <= $lastRow; $i++){
            $_table= array($i, $arr_data[$i]['A'], $arr_data[$i]['B']);
    
            $this->table->add_row($_table);
        }
    
        echo $this->table->generate();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。