Ecrit le flux CSV dans la sortie navigateur

@param  string $fileName    Nom du fichier généré
@param  string $enclosures  Caracère utiliser pour protéger les champs. Si null = aucun caractère.
@throws \Exception
496732
public function output($fileName, $enclosures = '"')
  {
    $this->enclosures = $enclosures;
    if (!$this->data) {
      throw new \Exception('Aucune donnée CSV à exporter.');
    }

    header('Content-Type: application/excel');
    header('Content-Disposition: attachment; filename="' . $fileName . '"');

    $fp = fopen('php://output', 'w');
    if ($this->useHeaders) {
      // Les entêtes sont les clés du tableau associatif
      $entetes = array_keys($this->data[0]);

      // Décodage des entêtes qui sont en UTF8 à la base
      foreach ($entetes as &$entete) {
        $entete = (is_string($entete)) ? iconv("UTF-8", "Windows-1252//TRANSLIT", $entete) : $entete;
      }

      // On utilise le troisième paramètre de fputcsv pour changer le séparateur par défaut de php
      fputcsv($fp, $entetes, ';', $this->enclosures);
    }

    // Écriture des données
    $this->writeDataInIO($fp);
    fclose($fp);
  }
699199
public function readFile() {
        if (!file_exists($this->filename)) {
            throw new Exception(__CLASS__ . ' couldn\'t find the CSV file.');
        }
        //Prepare fgetcsv parameters
        $length = isset($this->fgetcsvOptions['length']) ? $this->fgetcsvOptions['length'] : 0;
        $delimiter = isset($this->fgetcsvOptions['delimiter']) ? $this->fgetcsvOptions['delimiter'] : ',';
        $enclosure = isset($this->fgetcsvOptions['enclosure']) ? $this->fgetcsvOptions['enclosure'] : '"';
        $escape = isset($this->fgetcsvOptions['escape']) ? $this->fgetcsvOptions['escape'] : "\\";

        $lines = []; //Clear and set rows
        if (($fp = fopen($this->filename, 'r')) !== FALSE) {
            while (($line = fgetcsv($fp, $length, $delimiter, $enclosure, $escape)) !== FALSE) {
                array_push($lines, $line);
            }
        }
        //Remove unused lines from all lines
        for ($i = 0; $i < $this->startFromLine; $i++) {
            unset($lines[$i]);
        }
        return $lines;
    }
1278986
public function setTemplate( $fileName )
	{
		if( empty( $fileName ) )
			return FALSE;
			
		if( !file_exists( $fileName ) )
			throw new Exception_Template( Exception_Template::FILE_NOT_FOUND, $fileName );

		$this->fileName	= $fileName;
		$this->template = file_get_contents( $fileName );
		return TRUE;
	}
580216
public function queryFile($sFilename)
    {
        $fp = @fopen($sFilename, "r");
        if (!$fp) {
            /** @var Setup $oSetup */
            $oSetup = $this->getInstance("Setup");
            // problems with file
            $oSetup->setNextStep($oSetup->getStep('STEP_DB_INFO'));
            throw new Exception(sprintf($this->getInstance("Language")->getText('ERROR_OPENING_SQL_FILE'), $sFilename), Database::ERROR_OPENING_SQL_FILE);
        }

        $sQuery = fread($fp, filesize($sFilename));
        fclose($fp);

        if (version_compare($this->getDatabaseVersion(), "5") > 0) {
            //disable STRICT db mode if there are set any (mysql >= 5).
            $this->execSql("SET @@session.sql_mode = ''");
        }

        $aQueries = $this->parseQuery($sQuery);
        foreach ($aQueries as $sQuery) {
            $this->execSql($sQuery);
        }
    }
311134
static function export($list, $filename = 'data', $separator = ',', $enclosure = '"')
    {
        header('Content-Type: text/csv; charset=utf-8');
        header('Content-Disposition: attachment; filename=' . $filename . '.csv');

        $writer = Writer::createFromPath('php://output', 'w');
        $writer->insertAll($list); //using an array
    }
843578
public function setFiles($filenames)
    {
        if ($this->isReference()) {
            throw $this->tooManyAttributes();
        }
        if (!empty($filenames)) {
            $tok = strtok($filenames, ", \t\n\r");
            while ($tok !== false) {
                $fname = trim($tok);
                if ($fname !== "") {
                    $this->filenames[] = $tok;
                }
                $tok = strtok(", \t\n\r");
            }
        }
    }
770833
public function getBlobAsFile($container = '', $name = '', $localFileName = null)
    {
        $this->checkConnection();
        try {
            /** @var Container $container */
            $container = $this->blobConn->getContainer($container);
            if (empty($container)) {
                throw new \Exception("No container named '$container'");
            }

            $obj = $container->DataObject($name);

            if (!$obj->SaveToFilename($localFileName)) {
                throw new \Exception('');
            }
        } catch (\Exception $ex) {
            static::handleGuzzleException($ex);
            throw new DfException("Failed to retrieve blob '$name': " . $ex->getMessage());
        }
    }
1024778
static public function tryCreateFromFile($filename) {
		try {
			$instance = self::createFromFile($filename);
			return $instance;
		} catch (\Exception $exception) {
			return null;
		}
	}
1154980
public function handle($filename, $contents)
    {
        return $this->filesystem->has($filename) ? $this->filesystem->update($filename, $contents) : $this->filesystem->write($filename, $contents);
    }
617427
public function write(string $filename, string $contents): int
    {
        return (int)file_put_contents($filename, $contents);
    }
1019662
public function outputForceQuotesCSV($filepath, $csv)
    {
        $fqCsv = $this->arrayToCsv($csv, chr(9), '"', true, false);
        // Open for writing only; place the file pointer at the end of the file.
        // If the file does not exist, attempt to create it.
        $fp = fopen($filepath, 'a');

        // for some reason passing the preset delimiter/enclosure variables results in error
        // $this->delimiter $this->enclosure
        if (fwrite($fp, $fqCsv) == 0) {
            throw new \Exception('Problem writing CSV file');
        }
        fclose($fp);
    }
292133
public function loadFile( $fileName )
	{
		if( !file_exists( $fileName ) )
			throw new Exception( 'XML File "'.$fileName.'" is not existing.' );
		$this->document	= new DOMDocument();
		$this->document->load( $fileName );
		$this->xPath	= new DOMXpath( $this->document );
		return true;
	}
994295
public function saveAs($filename, $format = 'auto')
    {

        if ($format === 'auto') {
            $format =   strtolower(substr($filename, -5)) === '.json' ? 'json' : 'yaml';
        }
        if (strtolower($format) === 'json') {
            $content = $this->toJson();
        } else {
            $content = $this->toYaml();
        }
        if (file_put_contents($filename, $content) === false) {
            throw new Exception('Failed to saveAs("' . $filename . '", "'.$format.'")');
        }
    }
413379
public static function fileMime(string $filename, array $detalles = []) {
        if (isset($detalles['path'])) {
            $path = str_start(str_replace("\\", "/", $filename), str_finish(str_replace("\\", "/", $detalles['path']), '/'));
        } else {
            $path = $filename;
        }
        $ext = pathinfo($path, PATHINFO_EXTENSION);
        if (file_exists($path)) {
            $typesArray = config("sirgrimorum.mimebyext", []);
            $mimeType = "";
            if (!count($typesArray) == 0) {
                if (isset($typesArray[$ext])) {
                    $mimeType = $typesArray[$ext];
                }
            }
            $otro = $mimeType;
            if ($mimeType == "") {
                $finfo = finfo_open(FILEINFO_MIME_TYPE);
                $mimeType = finfo_file($finfo, public_path($path));
            }
            return $mimeType;
        } else {
            return false;
        }
    }
1239699
public function fromFile($filename)
        {
            if (!is_file($filename) || !is_readable($filename)) {
                throw new Exception(sprintf(
                    "File '%s' doesn't exist or not readable",
                    $filename
                ));
            }

            $this->directory = dirname($filename);

            set_error_handler(
                function ($error, $message = '', $file = '', $line = 0) use ($filename) {
                    throw new Exception(sprintf(
                        'Error reading INI file "%s": %s',
                        $filename, $message
                    ), $error);
                }, E_WARNING
            );
            $ini = parse_ini_file($filename, true);
            restore_error_handler();

            return $this->process($ini);
        }
81123
public static function appendContents($filename, $contents)
    {
        $result = file_put_contents($filename, $contents, \LOCK_EX | \LOCK_NB | \FILE_APPEND);
        if ($result === false) {
            throw new \RuntimeException("Cannot append to the file: " . $filename);
        }
    }
1269871
public static function toFile(Stringset $set, $filename)
    {
        try {
            $str = self::toString($set, $options);
            if (!file_exists($filename) || is_writable($filename)) {
                file_put_contents($filename, $str);
            } else {
                throw new Exception("Cannot write to file");
            }
        } catch (\Exception $e) {
            throw $e;
        }
    }