Reads entire file into a string.

@param string $filename The path to the file

@return string

@throws \InvalidArgumentException if the file path is not a string
@throws \RuntimeException if an error occurred
513467
protected function loadFile($filename)
    {
        if (!is_string($filename)) {
            throw new InvalidArgumentException(sprintf('%s expects parameter 1 to be string, %s given', __METHOD__, gettype($filename)));
        }

        try {
            $content = file_get_contents($filename);
        } catch (\Exception $exception) {
            throw new RuntimeException(sprintf('Could not load file %s', $filename));
        }

        if ($content === false) {
            throw new RuntimeException(sprintf('Could not load file %s', $filename));
        }

        return $content;
    }
226997
public function readFile($fileName)
	{
		if (!isset($this->format))
			$this->format = \PhpOffice\PhpSpreadsheet\IOFactory::identify($fileName);
		$objectreader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($this->format);
		if ($this->format == "Csv") {
			$objectreader->setDelimiter($this->CSVDelimiter);
			$objectreader->setInputEncoding($this->CSVEncoding);
		}
		$objectPhpExcel = $objectreader->load($fileName);

		$sheetCount = $objectPhpExcel->getSheetCount();

		$sheetDatas = [];

		if ($sheetCount > 1) {
			foreach ($objectPhpExcel->getSheetNames() as $sheetIndex => $sheetName) {
				if (isset($this->getOnlySheet) && $this->getOnlySheet != null) {
					if(!$objectPhpExcel->getSheetByName($this->getOnlySheet)) {
						return $sheetDatas;
					}
					$objectPhpExcel->setActiveSheetIndexByName($this->getOnlySheet);
					$indexed = $this->getOnlySheet;
					$sheetDatas[$indexed] = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
					if ($this->setFirstRecordAsKeys) {
						$sheetDatas[$indexed] = $this->executeArrayLabel($sheetDatas[$indexed]);
					}
					if (!empty($this->getOnlyRecordByIndex)) {
						$sheetDatas[$indexed] = $this->executeGetOnlyRecords($sheetDatas[$indexed], $this->getOnlyRecordByIndex);
					}
					if (!empty($this->leaveRecordByIndex)) {
						$sheetDatas[$indexed] = $this->executeLeaveRecords($sheetDatas[$indexed], $this->leaveRecordByIndex);
					}
					return $sheetDatas[$indexed];
				} else {
					$objectPhpExcel->setActiveSheetIndexByName($sheetName);
					$indexed = $this->setIndexSheetByName==true ? $sheetName : $sheetIndex;
					$sheetDatas[$indexed] = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
					if ($this->setFirstRecordAsKeys) {
						$sheetDatas[$indexed] = $this->executeArrayLabel($sheetDatas[$indexed]);
					}
					if (!empty($this->getOnlyRecordByIndex) && isset($this->getOnlyRecordByIndex[$indexed]) && is_array($this->getOnlyRecordByIndex[$indexed])) {
						$sheetDatas = $this->executeGetOnlyRecords($sheetDatas, $this->getOnlyRecordByIndex[$indexed]);
					}
					if (!empty($this->leaveRecordByIndex) && isset($this->leaveRecordByIndex[$indexed]) && is_array($this->leaveRecordByIndex[$indexed])) {
						$sheetDatas[$indexed] = $this->executeLeaveRecords($sheetDatas[$indexed], $this->leaveRecordByIndex[$indexed]);
					}
				}
			}
		} else {
			$sheetDatas = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
			if ($this->setFirstRecordAsKeys) {
				$sheetDatas = $this->executeArrayLabel($sheetDatas);
			}
			if (!empty($this->getOnlyRecordByIndex)) {
				$sheetDatas = $this->executeGetOnlyRecords($sheetDatas, $this->getOnlyRecordByIndex);
			}
			if (!empty($this->leaveRecordByIndex)) {
				$sheetDatas = $this->executeLeaveRecords($sheetDatas, $this->leaveRecordByIndex);
			}
		}

		return $sheetDatas;
	}
388260
protected function readStream($filename)
    {
        if (!file_exists($filename)) {
            throw new FileNotFoundException(sprintf('The file "%s" does not exists.', $filename));
        }

        $stream = fopen($filename, 'r');
        if (!$stream) {
            throw new FileNotFoundException(sprintf('The file "%s" can\'t be opened.', $filename));
        }

        return $stream;
    }
925395
private function fileReader($filename)
    {
        //Check if the path is defined
        if(empty($this->message_path))
        {
            $this->message_path = __DIR__.DIRECTORY_SEPARATOR.'messages'.DIRECTORY_SEPARATOR;
        }

        //Read message file and return content
        $message = file_get_contents($this->message_path.$filename.'.livia');
        //Return the message
        return $message;
    }
742534
public function loadConfig($fileName)
    {
        // Check if the given file exists
        if (file_exists($fileName)) {
            $file = file_get_contents($fileName);
        } else {
            // So the file can not be located
            // Check in config folder
            if (file_exists($this->getRootDir() . '/config/' . $fileName)) {
                $file = file_get_contents($this->getRootDir() . '/config/' . $fileName);
            } else {
                throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $fileName));
            }
        }

        $array  = Yaml::parse($file);

        // make sure we dealing with array first
        if (is_array($array)) {
            // Discover configuration
            foreach ($array as $key => $params) {
                // Import Resources
                if ($key == 'imports') {
                    foreach ($params as $resource) {
                        foreach ($resource as $key => $resourceName) {
                            if ($key == 'resource') {
                                $this->loadConfig($resourceName);
                            }
                        }
                    }
                // Direct parameters input
                } elseif ($key == 'parameters') {
                    foreach ($params as $paramName => $param) {
                        $this->config->setParameter($paramName, $param);
                    }
                // Save parameters in the Config
                } else {
                    $this->config->setParameter($key, $params);
                }
            }
        }

        return $this->config;
    }
306011
private function readFile($filename)
    {
        if (!file_exists($filename)) {
            throw new \Exception(sprintf('File not found: %s', $filename));
        }
        if (!is_readable($filename) || ($content = file_get_contents($filename)) === false) {
            throw new \Exception(sprintf('Failed to read file: %s', $filename));
        }

        return $content;
    }
1189387
public function load($filename)
    {
        $json = file_get_contents($filename);
        if (false === $json) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException("Unable to load file {$filename}");
            // @codeCoverageIgnoreEnd
        }

        $data = Utils::jsonDecode($json, true);
        if (is_array($data)) {
            foreach (Utils::jsonDecode($json, true) as $cookie) {
                $this->setCookie(new SetCookie($cookie));
            }
        } elseif (strlen($data)) {
            throw new \RuntimeException("Invalid cookie file: {$filename}");
        }
    }
165666
protected function readData($fileName)
    {
        $client   = new Client([ 'defaults' => [ 'timeout' => $this->getConfiguration()->getTimeout() ] ]);
        $response = $client->get($fileName);

        return $response->getBody();
    }
28685
public function writeFile($filename)
    {
        $file = $this->getAttribute('file');
        if (empty($file) && !$this->getIsNewRecord()) {
            $file = $this->refreshFile();
        }

        if (empty($file)) {
            throw new InvalidParamException('There is no file associated with this object.');
        } elseif ($file instanceof Download) {
            return ($file->toFile($filename) == $file->getSize());
        } elseif ($file instanceof UploadedFile) {
            return copy($file->tempName, $filename);
        } elseif (is_string($file)) {
            if (file_exists($file)) {
                return copy($file, $filename);
            }
            throw new InvalidParamException("File '{$file}' does not exist.");
        }

        throw new InvalidParamException('Unsupported type of "file" attribute.');
    }
40851
public function readFile($filename)
    {
        if (!is_string($filename))
            throw new IniReadingException('The expected type is string');

        if (!file_exists($filename) || !is_readable($filename))
            throw new IniReadingException(sprintf("The file %s doesn't exist or is not readable", $filename));

        if (function_exists('file_get_contents')) {
            $ini = file_get_contents($filename);
        } elseif (function_exists('file')) {
            $ini = file($filename);
            if ($ini !== false)
                $ini = implode("\n", $ini);
        } elseif (function_exists('fopen') && function_exists('fread')) {
            $handle = fopen($filename, 'r');
            if (!$handle)
                return false;
            $ini = fread($handle, filesize($filename));
            fclose($handle);
        } else {
            return false;
        }

        if ($ini === false)
            throw new IniReadingException(sprintf('Impossible to read the file %s', $filename));

        return $this->readString($ini);
    }
559216
public static function read($fileName)
    {
        if (!file_exists($fileName)) {
            throw new RuntimeException($fileName.' not exist');
        }
        if (!is_readable($fileName)) {
            throw new RuntimeException($fileName.' not readable');
        }

        $fh = fopen($fileName, "r");
        $data = fread($fh, filesize($fileName));
        fclose($fh);

        return $data;
    }
887205
public function read($fileName=null)
    {
        $this->_resetFileName($fileName);

        $manifest = array();
        $hashLen = ($this->hashEncoding == 'sha1') ? 40 : 32;
        $lines = readLines($this->fileName, $this->fileEncoding);

        foreach ($lines as $line) {
            $hash = trim(substr($line, 0, $hashLen));
            $payload = trim(substr($line, $hashLen));

            if (strlen($payload) > 0) {
                $manifest[$payload] = $hash;
            }
        }

        $this->data = $manifest;
        return $manifest;
    }
775194
public static function getContents($filename)
    {
        $file = fopen($filename, "r");

        if ($file === false) {
            throw new \RuntimeException("Cannot read the file: {$filename}");
        }

        $data = [];
        while ($row = fgetcsv($file)) {
            $data[] = $row;
        }

        fclose($file);

        return $data;
    }
430693
protected function loadTokenFromFile($filename)
    {
        if (strpos($filename, '/') !== 0 && strpos($filename, '\\') !== 0) {
            $filename = $this->config->getUserConfigDir() . '/' . $filename;
        }

        $content = file_get_contents($filename);
        if ($content === false) {
            throw new \RuntimeException('Failed to read file: ' . $filename);
        }

        return trim($content);
    }
1339629
public function readdata($filename) {

        // Find if we are importing a .txt file.
        if (strtolower(pathinfo($filename, PATHINFO_EXTENSION)) == 'txt') {
            if (!is_readable($filename)) {
                $this->error(get_string('filenotreadable', 'error'));
                return false;
            }
            return file($filename);
        }
        // We are importing a zip file.
        // Create name for temporary directory.
        $this->tempdir = make_request_directory();
        if (is_readable($filename)) {
            if (!copy($filename, $this->tempdir . '/webct.zip')) {
                $this->error(get_string('cannotcopybackup', 'question'));
                fulldelete($this->tempdir);
                return false;
            }
            $packer = get_file_packer('application/zip');
            if ($packer->extract_to_pathname($this->tempdir . '/webct.zip', $this->tempdir, null, null, true)) {
                $dir = $this->tempdir;
                if ((($handle = opendir($dir))) == false) {
                    // The directory could not be opened.
                    fulldelete($this->tempdir);
                    return false;
                }
                // Create arrays to store files and directories.
                $dirfiles = array();
                $dirsubdirs = array();
                $slash = '/';

                // Loop through all directory entries, and construct two temporary arrays containing files and sub directories.
                while (false !== ($entry = readdir($handle))) {
                    if (is_dir($dir. $slash .$entry) && $entry != '..' && $entry != '.') {
                        $dirsubdirs[] = $dir. $slash .$entry;
                    } else if ($entry != '..' && $entry != '.') {
                        $dirfiles[] = $dir. $slash .$entry;
                    }
                }
                if ((($handle = opendir($dirsubdirs[0]))) == false) {
                    // The directory could not be opened.
                    fulldelete($this->tempdir);
                    return false;
                }
                while (false !== ($entry = readdir($handle))) {
                    if (is_dir($dirsubdirs[0]. $slash .$entry) && $entry != '..' && $entry != '.') {
                        $dirsubdirs[] = $dirsubdirs[0]. $slash .$entry;
                    } else if ($entry != '..' && $entry != '.') {
                        $dirfiles[] = $dirsubdirs[0]. $slash .$entry;
                    }
                }
                return file($dirfiles[1]);
            } else {
                $this->error(get_string('cannotunzip', 'question'));
                fulldelete($this->tempdir);
            }
        } else {
            $this->error(get_string('cannotreaduploadfile', 'error'));
            fulldelete($this->tempdir);
        }
        return false;
    }
709839
static public function getUploadFilePath($filename)
    {
        if ($filename) {
            $filename = static::getUploadFileRelativePath($filename);
            
            if (static::isRootImageFile($filename)) {
                
                return static::getWebRootPath() . $filename;
            }
            
            $filename = static::getUploadPath() . $filename;
        }
        
        return $filename;
    }
604007
protected function getFullPath($fileName)
    {
        if (!is_string($fileName)) {
            throw new \InvalidArgumentException('the given path is invalid');
        }

        $fileName = trim($fileName);

        if (realpath($fileName) && !(basename($fileName) === $fileName)) {
            return realpath($fileName);
        }

        $fullName = implode(DIRECTORY_SEPARATOR, array($this->configurationFileDir, $fileName));

        if (file_exists($fullName)) {
            return realpath($fullName);
        }

        throw new \InvalidArgumentException('The specified path \'' . $fullName . '\' does not exist');
    }