Create excel file and store in tmp dir

@param string $filename
@param string $format
@param bool   $disconnect
@throws \Exception
@return array
510794
private function writeFileToTmp($filename, $format = 'Excel2007', $disconnect = true)
    {
        $path = sprintf('%s/%s', $this->tempPath, $filename);
        $objWriter = \PHPExcel_IOFactory::createWriter($this->file, $format);
        $objWriter->save($path);

        if ($disconnect) {
            $this->file->disconnectWorksheets();
            unset($this->file);
        }

        $this->fileName = $filename;
        $this->filePath = $path;

        return array($path, $filename);
    }
1272007
public static function insertIntoFile($filename, $anchorString, $offset=0, $content)
    {
        if(!file_exists($filename)){
            throw new \Exception('Target File '.$filename.' does not exists');
        }
        $fileLines = file($filename);
        $resLines = [];
        $foundAnchor = false;
        foreach ($fileLines as $line) {
            if(self::contains($line, $anchorString)){
                $foundAnchor = true;
                // decrease the offset value until 0 to locate the target line
            } else {
                if($foundAnchor){
                    $offset = $offset - 1;
                }
            }
            if($offset == 0 && $foundAnchor ){
                if(is_array($content)){
                    $resLines = array_merge($resLines, $content);
                } else {
                    $resLines[] = $content;
                }
            }
            $resLines[] = $line;
        }
        $resLines = implode('',$resLines);
        file_put_contents($filename, $resLines);
    }
379771
public static function write($filename, $content, $mode = 0666)
    {
        self::ensureFileSystem()->dumpFile($filename, $content, $mode);
    }
1173598
public function addFile($filename, FormatChainInterface $formatChain = null)
    {
        if (null === $formatChain) {
            if (null === $this->formatGuesser) {
                throw new FormatGuesserRequiredException();
            }

            $formatChain = $this->formatGuesser->guess($filename);
        }

        $this->files[] = new File($filename, $formatChain);

        return $this;
    }
332690
public function delete(string $filename): DeleteCommand
    {
        /** @var DeleteCommand $command */
        $command = $this->builder->build(DeleteCommand::class);
        $command->byFilename($filename);

        return $command;
    }
271004
public function createImage($width, $height, $format)
    {
        $image = new \Imagick();
        $pixel = new \ImagickPixel('none');
        $image->newImage(intval($width), intval($height), $pixel);
        $image->setImageFormat($format);
        $this->colorNumber = $image->getImageColors();
        $this->pixelNumber = 0;
        $content = $image->getimageblob();
        $image->destroy();
        unset($image);
        return $content;
    }
1234775
public function setSimpleLog($filename, $format = '{code}')
    {
        if ($this->logger && !($this->logger instanceof \Monolog\Logger)) {
            return false;
        }

        $handler = new \Monolog\Handler\StreamHandler($filename);
        $handler->setFormatter(new \Monolog\Formatter\LineFormatter('%message%'));
        $log = new \Monolog\Logger('HTTP Log', [$handler]);

        return $this->setLogger($log, $format);
    }
129447
public function getResponse($format, $filename, SourceIteratorInterface $source)
    {
        switch ($format) {
            case 'xls':
                $writer = new XlsWriter('php://output');
                $contentType = 'application/vnd.ms-excel';

                break;
            case 'xml':
                $writer = new XmlWriter('php://output');
                $contentType = 'text/xml';

                break;
            case 'json':
                $writer = new JsonWriter('php://output');
                $contentType = 'application/json';

                break;
            case 'csv':
                $writer = new CsvWriter('php://output', ',', '"', '\\', true, true);
                $contentType = 'text/csv';

                break;
            default:
                throw new \RuntimeException('Invalid format');
        }

        $callback = static function () use ($source, $writer) {
            $handler = Handler::create($source, $writer);
            $handler->export();
        };

        return new StreamedResponse($callback, 200, [
            'Content-Type' => $contentType,
            'Content-Disposition' => sprintf('attachment; filename="%s"', $filename),
        ]);
    }
645154
public static void writeReadDeleteDocument(DatabaseClient client, String filename, String format) throws IOException {
    // create a manager for documents of any format
    GenericDocumentManager docMgr = client.newDocumentManager();

    InputStream docStream = Util.openStream("data"+File.separator+filename);
    if (docStream == null)
      throw new IOException("Could not read document example");

    // create an identifier for the document
    String docId = "/example/"+filename;

    // create a handle for the document
    InputStreamHandle writeHandle = new InputStreamHandle();
    writeHandle.set(docStream);

    // write the document
    docMgr.write(docId, writeHandle);

    // create a handle to receive the document content
    BytesHandle readHandle = new BytesHandle();

    // read the document content
    docMgr.read(docId, readHandle);

    // access the document content
    byte[] document = readHandle.get();

    // ... do something with the document content ...

    // delete the document
    docMgr.delete(docId);

    System.out.println("Wrote, read, and deleted /example/"+filename+
      " content with "+document.length+" bytes in the "+format+" format");
  }
245318
public function create($filename, $width, $height = null)
    {
        try {
            $image = app('image')->make($this->file->realPath)
                ->fit($width, ($height ?: $width))
                ->encode();

            $this->file->storage->put($this->file->path($filename), $image);
        } catch (NotReadableException $e) {
            return null;
        }

        return $this->file->storage->url($this->file->path($filename));
    }
47317
public static function load($fileName, $separate='/')
    {
        $instance = new static($fileName);
        $instance->setSeparate($separate);

        $filePath = $instance->getFilePath(self::getDir(), $fileName);

        if ($filePath) {
            $instance->setAll($instance->loadFile($filePath));
        } else {
            throw new FileNotExistException('File '. $fileName .' does not exist');
        }

        return $instance;
    }
1192037
public function writeFile($filename)
    {

        if (!$filename) {
            trigger_error(ReporticoLang::templateXlate("UNABLE_TO_SAVE") . templateXlate("SPECIFYXML"), E_USER_ERROR);
            return false;
        }

        if (!preg_match("/\.xml$/", $filename)) {
            $filename = $filename . ".xml";
        }

        $projdir = $this->query->projects_folder . "/" . ReporticoApp::getConfig("project");
        if (!is_file($projdir)) {
            ReporticoUtility::findFileToInclude($projdir, $projdir);
        }

        if ($projdir && is_dir($projdir)) {

            $fn = $projdir . "/" . $filename;
            if (!($fd = @fopen($fn, "w"))) {

                trigger_error("Unable to open project file " . $fn . " for writing. Check folder and file permissions " , E_USER_ERROR);
                return false;
            }
        } else {


            trigger_error("Unable to open project area " . ReporticoApp::getConfig("project") . " to save file $filename " .
                $this->query->reports_path . "/" . $filename . " Not Found", E_USER_ERROR);
        }

        if (!fwrite($fd, '<?xml version="' . $this->xml_version . '"?>')) {
            return false;
        }

        $xmltext = $this->xmldata->unserialize();
        if (!fwrite($fd, $xmltext)) {
            return false;
        }

        fclose($fd);

    }
1020652
private function writeTemplateToFile($fileContent, $filename, $force = false)
    {
        $created = false;
        if ($force || !file_exists($filename)) {
            try {
                $this->cache->storeData($filename, $fileContent, Cache::TEXT, true);
                $created = true;
            } catch (\Exception $e) {
                Logger::log($e->getMessage(), LOG_ERR);
            }
        } else {
            Logger::log($filename . t(' not exists or cant write'), LOG_ERR);
        }
        return $created;
    }
1369352
function Save($filename)
    {
        $result = @$this->domDoc->save($filename);
        
        if ($result === false)
            throw new \Exception("RSS Feed saviing to '$filename' failed");
        
        return $result;
    }
487380
public function saveToFile($filePath,$format = 'csvforexcel')
    {
        $this->format(Format::get($format));
        $this->run();

        $this->data->saveToFile($filePath);

        return true;
    }
655920
public function write(
        string $filename,
        string $data,
        int $mode = null,
        bool $ensureDirectory = false,
        bool $append = false
    ): bool {
        $mode = $mode ?? self::DEFAULT_FILE_MODE;

        try {
            if ($ensureDirectory) {
                $this->ensureDirectory(dirname($filename), $mode);
            }

            if ($this->exists($filename)) {
                //Forcing mode for existed file
                $this->setPermissions($filename, $mode);
            }

            $result = file_put_contents(
                $filename,
                $data,
                $append ? FILE_APPEND | LOCK_EX : LOCK_EX
            );

            if ($result !== false) {
                //Forcing mode after file creation
                $this->setPermissions($filename, $mode);
            }
        } catch (\Exception $e) {
            throw new WriteErrorException($e->getMessage(), $e->getCode(), $e);
        }

        return $result;
    }
776101
public static function csvFileToArray($filename='', $delimiter=',')
    {
        $header = null;
        $data = [];
        if (($handle = fopen($filename, 'r')) !== false) {
            while (($row = fgetcsv($handle, 1000, $delimiter)) !== false) {
                if (!$header) {
                    $header = $row;
                } else {
                    $data[] = array_combine($header, $row);
                }
            }
            fclose($handle);
        }

        return $data;
    }