PHP CodeIgniter:文件不会得到足够快的上传,它继续没有该文件的过程 [英] PHP CodeIgniter: File doesn't get uploaded fast enough and it continues the process without the file

查看:82
本文介绍了PHP CodeIgniter:文件不会得到足够快的上传,它继续没有该文件的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个提交文件代码,用于将Excel文件上传到我的服务器,然后通过该函数使用它。

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

这样做时:

    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";

它给我这个输出:


加载文件.xlsx时出错:无法打开
/var/www/html/tools/files/automation/1/.xlsx进行阅读!文件
不存在。

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?

推荐答案

如果您要以用户或任何您需要的方式上传差异文件夹中的文件

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();
}

这篇关于PHP CodeIgniter:文件不会得到足够快的上传,它继续没有该文件的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆