src/Dev/CsvBulkLoader.php
protected function splitFile($path, $lines = null)
    {
        Deprecation::notice('5.0', 'splitFile is deprecated, please process files using a stream');
        $previous = ini_get('auto_detect_line_endings');

        ini_set('auto_detect_line_endings', true);

        if (!is_int($lines)) {
            $lines = $this->config()->get("lines");
        }

        $new = $this->getNewSplitFileName();

        $to = fopen($new, 'w+');
        $from = fopen($path, 'r');

        $header = null;

        if ($this->hasHeaderRow) {
            $header = fgets($from);
            fwrite($to, $header);
        }

        $files = array();
        $files[] = $new;

        $count = 0;

        while (!feof($from)) {
            fwrite($to, fgets($from));

            $count++;

            if ($count >= $lines) {
                fclose($to);

                // get a new temporary file name, to write the next lines to
                $new = $this->getNewSplitFileName();

                $to = fopen($new, 'w+');

                if ($this->hasHeaderRow) {
                    // add the headers to the new file
                    fwrite($to, $header);
                }

                $files[] = $new;

                $count = 0;
            }
        }

        fclose($to);

        ini_set('auto_detect_line_endings', $previous);

        return $files;
    }
protected function splitFile($path, $lines = null)
    {
        Deprecation::notice('5.0', 'splitFile is deprecated, please process files using a stream');
        $previous = ini_get('auto_detect_line_endings');

        ini_set('auto_detect_line_endings', true);

        if (!is_int($lines)) {
            $lines = $this->config()->get("lines");
        }

        $new = $this->getNewSplitFileName();

        $to = fopen($new, 'w+');
        $from = fopen($path, 'r');

        $header = null;

        if ($this->hasHeaderRow) {
            $header = fgets($from);
            fwrite($to, $header);
        }

        $files = array();
        $files[] = $new;

        $count = 0;

        while (!feof($from)) {
            fwrite($to, fgets($from));

            $count++;

            if ($count >= $lines) {
                fclose($to);

                // get a new temporary file name, to write the next lines to
                $new = $this->getNewSplitFileName();

                $to = fopen($new, 'w+');

                if ($this->hasHeaderRow) {
                    // add the headers to the new file
                    fwrite($to, $header);
                }

                $files[] = $new;

                $count = 0;
            }
        }

        fclose($to);

        ini_set('auto_detect_line_endings', $previous);

        return $files;
    }
protected function splitFile ( $ path , $ lines = null ) { Deprecation :: notice ( '5.0' , 'splitFile is deprecated, please process files using a stream' ) ; $ previous = ini_get ( 'auto_detect_line_endings' ) ; ini_set ( 'auto_detect_line_endings' , true ) ; if ( ! is_int ( $ lines ) ) { $ lines = $ this -> config ( ) -> get ( "lines" ) ; } $ new = $ this -> getNewSplitFileName ( ) ; $ to = fopen ( $ new , 'w+' ) ; $ from = fopen ( $ path , 'r' ) ; $ header = null ; if ( $ this -> hasHeaderRow ) { $ header = fgets ( $ from ) ; fwrite ( $ to , $ header ) ; } $ files = array ( ) ; $ files [ ] = $ new ; $ count = 0 ; while ( ! feof ( $ from ) ) { fwrite ( $ to , fgets ( $ from ) ) ; $ count ++ ; if ( $ count >= $ lines ) { fclose ( $ to ) ; // get a new temporary file name, to write the next lines to $ new = $ this -> getNewSplitFileName ( ) ; $ to = fopen ( $ new , 'w+' ) ; if ( $ this -> hasHeaderRow ) { // add the headers to the new file fwrite ( $ to , $ header ) ; } $ files [ ] = $ new ; $ count = 0 ; } } fclose ( $ to ) ; ini_set ( 'auto_detect_line_endings' , $ previous ) ; return $ files ; }
Splits a large file up into many smaller files.

@param string $path Path to large file to split
@param int $lines Number of lines per file

@return array List of file paths
Splits a large file up into many smaller files .