Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP CSVImporter_Php_File_Csv_Import - Fatal编程技术网

PHP CSVImporter

PHP CSVImporter,php,file,csv,import,Php,File,Csv,Import,我有一个名为csvimporterv3forphp的脚本,我曾经在一个网站上运行过,它运行得很好。几年后,我现在已经挖掘出了相同的脚本用于另一个项目,除了CSV文件之外,所有的工作都正常,作为一个长行读取,而不是头行和多行 这是脚本的一部分 你知道为什么它会被解读为一条长线吗 <?php // Reference session variable for short-hand $f = &$_SESSION['csv_file']; //

我有一个名为csvimporterv3forphp的脚本,我曾经在一个网站上运行过,它运行得很好。几年后,我现在已经挖掘出了相同的脚本用于另一个项目,除了CSV文件之外,所有的工作都正常,作为一个长行读取,而不是头行和多行

这是脚本的一部分

你知道为什么它会被解读为一条长线吗

<?php 

//  Reference session variable for short-hand
        $f = &$_SESSION['csv_file'];

        //  Open file - fp = file pointer
        if (!$fp = @fopen($f, 'r')) {

            error(L_ERROR_PREVIEW_NO_FILE);

        } else {

            //  Array to store each row to be inserted
            $batch = array();

            //  Row counter
            $rc = 0;

            //  Work out starting row
            switch ($_SESSION['csv_first_row']) {
                case 'data':
                    $start_row = 0;
                break;

                default:
                    $start_row = 1;
            }

            //  Get contents, while below preview limit and there's data to be read
            while ($data = fgetcsv($fp, 1024, delimiter_to_char($_SESSION['csv_delimiter']))) {

                if ($rc < $start_row) {

                    //  Incremement counter
                    $rc++;

                    //  Go to next loop
                    continue;

                } else {

                    //  Array to store data to be inputted
                    $values = array();

                    //  Loop data
                    for ($i = 0; $i < count($data); $i++) {

                        //  If data is wanted, put data into array
                        if (array_key_exists($i, $column_index)) {
                            $values[$column_index[$i]] = $data[$i];
                        }

                    }

                    //  Sort array into correct order by index
                    ksort($values);

                    //  Join values together and store in array
                    $batch[] = '("' . implode('", "', str_replace('"', '\"', $values)) . '","'.$accti.'","'.$impt.'")';

                }

            }


        }
            //  Close the file
            fclose($fp); 

我在代码顶部添加了这个,现在一切都正常了

ini_set('auto_detect_line_endings', true);

$\u SESSION['csv\u delimiter']
的值是多少?是否设置了
$\u SESSION['csv\u delimiter']
?尝试
var\u转储($\u会话)
并查看是否存在早期设置的“'csv_delimiter'”,我刚刚为此站点压缩了它。值为“
”,“
单个字段被分隔,仅当在CSV文件中读取新行时,它被追加到前一行的末尾,这实际上创建了一个大行。