Read a file and returns text content

@param string $file File path to read
@return string File content
@throws \Exception
5114
public function read(string $file): string
    {
        $destFile = tempnam(sys_get_temp_dir(), 'pdf_to_text_');

        $command = sprintf(
            'pdftotext -layout %s %s',
            escapeshellarg(realpath($file)),
            escapeshellarg($destFile)
        );

        $return = 0;
        $output = system($command, $return);

        $content = file_get_contents($destFile);
        unlink($destFile);

        switch ($return) {
            case 0:
                return $content;

            default:
                throw new \Exception($command . PHP_EOL . $output, $return);
        }
    }
610163
private function read_file($file)
  {
    $handler = fopen($file, "r");
    $file_content = fread($handler, filesize($file));
    fclose($handler);

    return $file_content;
  }
394971
protected static function getPathFromFile(File $file)
    {
        $path = tempnam(TEMP_PATH, 'pdftextextractor_');
        if (false === $path) {
            throw new Exception(static::class . '->getPathFromFile() could not allocate temporary file name');
        }

        // Append extension to temp file if one is set
        if ($file->getExtension()) {
            $path .= '.' . $file->getExtension();
        }

        // Remove any existing temp files with this name
        if (file_exists($path)) {
            unlink($path);
        }

        $bytesWritten = file_put_contents($path, $file->getStream());
        if (false === $bytesWritten) {
            throw new Exception(static::class . '->getPathFromFile() failed to write temporary file');
        }

        return $path;
    }
19366
protected function _fileGetContents($file)
    {
        $result = false;
        if (!is_file($file)) {
            return false;
        }
        $f = @fopen($file, 'rb');
        if ($f) {
            if ($this->_options['file_locking']) @flock($f, LOCK_SH);
            $result = stream_get_contents($f);
            if ($this->_options['file_locking']) @flock($f, LOCK_UN);
            @fclose($f);
        }
        return $result;
    }
972050
protected function getFileContents($file, $line){
        if(!is_string($file) || !is_int($line)
            || !is_file($file) || !is_readable($file)
        ){
            return null;
        }

        $file       = new \SplFileObject($file, "r");
        $current    = 1;
        $contents   = [];
        $min        = $line - 3;
        $max        = $line + 3;

        foreach($file as $row){
            if($min <= $current && $current <= $max){
                $contents[$current] = $row;
            }

            $current++;
        }

        if(empty($contents)){
            return null;
        }

        return $contents;
    }
1182980
public function getContents($file)
    {
        $file = $this->basePath.'/'.ltrim($file, '/\\');

        if(!file_exists($file))
            throw new \Exedra\Exception\NotFoundException("File [$file] not found");

        return file_get_contents($file);
    }
616419
public static function get(
        $file
    ) {
        if (is_string($file)) {
            $file = new \SplFileInfo($file);
        }

        $extension = mb_strtolower($file->getExtension());
        if ('' === $extension) {
            return static::MIME_TYPE_IF_UNKNOWN;
        }

        if (array_key_exists($extension, static::$mimeTypes)) {
            return static::$mimeTypes[$extension];
        }

        if (function_exists('finfo_open') && $file->isFile()) {
            $path = $file->getPath();

            $fileInfo = finfo_open(FILEINFO_MIME);
            $mimeType = finfo_file($fileInfo, $path);
            finfo_close($fileInfo);

            return $mimeType;
        }

        return static::MIME_TYPE_IF_UNKNOWN;
    }
1370420
public function read($file)
    {
        $document = new \DOMDocument();
        $errorToExceptionContext = new ErrorToExceptionContext(E_WARNING, function () use ($file, $document) {
            $document->load($file);
        });
        $errorToExceptionContext->invoke();

        return $this->readDocument($document, pathinfo($file, PATHINFO_FILENAME));
    }
11928
public function get($file)
    {
        $basepath = $this->config['basepath'];
        $suffix = $this->config['suffix'];
        $target = "$basepath/$file{$suffix}";

        if (!is_readable($target)) {
            throw new \Exception(t("No such file content: @FILENAME", ["@FILENAME" => $target]));
        }

        $filter  = $this->config['textfilter'];
        $content = file_get_contents($target);
        $content = $this->di->textFilter->doFilter($content, $filter);

        return $content;
    }
266056
private function getFileContents($file)
    {
        if (!isset($this->filesContent[$file])) {
            $this->filesContent[$file] = file_exists($file) ? file($file) : [];
        }

        return $this->filesContent[$file];
    }
707302
public function read() {
		
		$id = $this->getId();
		$path = $this->getPath($id);
		if (!is_readable($path)) {
			throw new Exception("Expected path $path is not readable");
		}

		return file_get_contents($path);
	}
1303690
public function parse($file)
    {
        if (isset($this->_tree[$file])) {
            return $this->_tree[$file];
        }
        $parser = $this->_classes['parser'];
        return $this->_tree[$file] = $parser::parse(file_get_contents($file), ['lines' => true]);
    }
377174
public function fetch($file) {
		$this->path = $this->path != '' ? $this->path : $this->basePath . '/' . $this->directory . '/' . $file . '.' . $this->fileExtension;
		
		extract($this->vars);			// Extract the vars to local namespace
		ob_start();						// Start output buffering
		include($this->path);					// Include the file
		$contents = ob_get_contents();	// Get the contents of the buffer
		ob_end_clean();					// End buffering and discard
		return $contents;				// Return the contents
	}
444666
private function openFile($file)
    {
        if (!(is_readable($file) && is_file($file))) {
            $this->throwException('FILE_EXISTS', $file);
        }
        $handle = fopen($file, 'rb');
        if (!$handle) {
            $this->throwException('FILE_OPEN', $file);
        }
        return $handle;
    }
716254
public function read()
    {
        $result = '';
        $ht = $this->getHTaccessFilename();
        $fs = $this->getFilesystem();
        if (@$fs->isFile($ht)) {
            $result = @$fs->get($ht);
            if ($result === false) {
                throw new Exception("Failed to read from file $ht");
            }
        }

        return $result;
    }
852008
public static function get(String $file) : stdClass
    {
        $file = self::rpath($file);

        if( ! is_file($file) )
        {
            throw new Exception\FileNotFoundException(NULL, $file);
        }

        return (object)
        [
            'basename'   => self::pathInfo($file, 'basename'),
            'size'       => filesize($file),
            'date'       => filemtime($file),
            'readable'   => is_readable($file),
            'writable'   => is_writable($file),
            'executable' => is_executable($file),
            'permission' => fileperms($file)
        ];
    }
251673
private function getFileContents($file) {
		$content = file_get_contents($file);

		// Remove UTF-8 BOM
		if (substr($content, 0, 3) === pack("CCC", 0xef, 0xbb, 0xbf))
			$content = substr($content, 3);

		return $content;
	}