无法打开流:没有这样的文件或目录 Codeignter

毫米

我正在尝试将数据从 csv 文件上传到我的 sql server 数据库。

所以我创建了这个 csv 阅读器库:

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class CSVReader
{

    var $fields;
    /** columns names retrieved after parsing */
    var $separator = ';';
    /** separator used to explode each line */
    var $enclosure = '"';
    /** enclosure used to decorate each field */

    var $max_row_size = 4096;
    /** maximum row size to be used for decoding */

    function parse_file($p_Filepath)
    {

        $file = fopen($p_Filepath, 'r');
        $this->fields = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure);
        $keys_values = explode(',', $this->fields[0]);

        $content    =   array();
        $keys   =   $this->escape_string($keys_values);

        $i  =   1;
        while (($row = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure)) != false) {
            if ($row != null) { // skip empty lines
                $values =   explode(',', $row[0]);
                if (count($keys) == count($values)) {
                    $arr    =   array();
                    $new_values =   array();
                    $new_values =   $this->escape_string($values);
                    for ($j = 0; $j < count($keys); $j++) {
                        if ($keys[$j] != "") {
                            $arr[$keys[$j]] =   $new_values[$j];
                        }
                    }

                    $content[$i] =   $arr;
                    $i++;
                }
            }
        }
        fclose($file);
        return $content;
    }

    function escape_string($data)
    {
        $result =   array();
        foreach ($data as $row) {
            $result[]   =   str_replace('"', '', $row);
        }
        return $result;
    }
}
?>

我添加了这部分 JS 代码以将我的文件从视图发送到控制器:

$("#form").on('submit', (function(e) {
    e.preventDefault();

    $.ajax({
        url: "../Commande/sendToIncadeaWithFile",
        type: "POST",
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData: false,
        success: function() {

        },
        error: function(e) {

        }
    });
}));

然后我试图从文件中开始对我的数据检索部分进行编码,以便我可以将它们发送到模型以便将它们插入到数据库中。

我刚开始尝试通过这样做来查看是否正确检索了数据:

<?php
if ($_FILES['file']) {

    $fileName = $_FILES["file"]["name"];
    var_dump($_FILES["file"]["size"]);
    $cofing['upload_path'] = './upload/';
    $cofing['allowed_types'] = 'csv';
    $this->load->library('upload', $cofing);

    if (!$this->upload->do_upload('file')) {
        echo $this->upload->display_errors();
    } else {
        $data = $this->upload->data();

        $result =   $this->csvreader->parse_file($fileName);
        var_dump($result);
    }
}
?>

但我收到此错误:

无法打开流:没有这样的文件或目录

这是指向fopen指令。

你能帮我解决这个问题吗?

Jijin

因为您没有指向完整路径(包括文件夹)

尝试

<?php
 $data = $this->upload->data();
    //$csvFile=FCPATH."upload/".$fileName; //php way (uploaded filepath and filename )
  $csvFile=$data['full_path']; //codeigniter way
  $result =   $this->csvreader->parse_file($csvFile);

?>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法打开流:没有这样的文件或目录

无法打开流:没有这样的文件或目录(Laravel)

无法打开流:没有这样的文件或目录

无法打开流:没有这样的文件或目录问题

如何从 codeignter 文件夹中删除正常通知

fopen:无法打开流:没有这样的文件或目录 - 但文件/目录存在

在s3上上传文件:无法打开流:没有这样的文件或目录

文件存在,但是fopen“无法打开流,没有这样的文件或目录”

文件存在,但PHP抛出“无法打开流:没有这样的文件或目录”

文件存在但收到无法打开流的警告:没有这样的文件或目录

include(MYPDF.php):无法打开流:没有这样的文件或目录yii tcpdf

Laravel classloader.php错误无法打开流:没有这样的文件或目录

file_get_contents():无法打开流:没有这样的文件或目录

PHP 警告:require_once:无法打开流:中没有这样的文件或目录

Zend include_once(myphpfile):无法打开流:没有这样的文件或目录

file_get_content:无法打开流:没有这样的文件或目录

move_uploaded_file(...):无法打开流:没有这样的文件或目录

无法打开流:...中没有这样的文件或目录?特定于PHP

file_put_contents(xxx.pdf):无法打开流:没有这样的文件或目录”

yii PDO.php错误:无法打开流:没有这样的文件或目录

PHP-无法打开流:没有这样的文件或目录

警告:未知:无法打开流:在第0行的“未知”中没有这样的文件或目录

Magento后端扩展无法打开流:没有这样的文件或目录

php artisan migration:reset无法打开流:没有这样的文件或目录

app / bootstrap.php.cache:无法打开流:没有这样的文件或目录

include_once(): 无法打开流:没有这样的文件或目录 - PHP

PHP / SQL-无法打开流:没有这样的文件或目录

Yii2:无法打开流:没有这样的文件或目录

警告:require_once():无法打开流:中没有这样的文件或目录