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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分