@param string $filepath
@param boolean $preview

@return null|BulkLoader_Result
337615
protected function processAll($filepath, $preview = false)
    {
        $previousDetectLE = ini_get('auto_detect_line_endings');

        ini_set('auto_detect_line_endings', true);
        $result = BulkLoader_Result::create();

        try {
            $filepath = Director::getAbsFile($filepath);
            $csvReader = Reader::createFromPath($filepath, 'r');

            $tabExtractor = function ($row, $rowOffset, $iterator) {
                foreach ($row as &$item) {
                    // [SS-2017-007] Ensure all cells with leading tab and then [@=+] have the tab removed on import
                    if (preg_match("/^\t[\-@=\+]+.*/", $item)) {
                        $item = ltrim($item, "\t");
                    }
                }
                return $row;
            };

            if ($this->columnMap) {
                $headerMap = $this->getNormalisedColumnMap();
                $remapper = function ($row, $rowOffset, $iterator) use ($headerMap, $tabExtractor) {
                    $row = $tabExtractor($row, $rowOffset, $iterator);
                    foreach ($headerMap as $column => $renamedColumn) {
                        if ($column == $renamedColumn) {
                            continue;
                        }
                        if (array_key_exists($column, $row)) {
                            if (strpos($renamedColumn, '_ignore_') !== 0) {
                                $row[$renamedColumn] = $row[$column];
                            }
                            unset($row[$column]);
                        }
                    }
                    return $row;
                };
            } else {
                $remapper = $tabExtractor;
            }

            if ($this->hasHeaderRow) {
                $rows = $csvReader->fetchAssoc(0, $remapper);
            } elseif ($this->columnMap) {
                $rows = $csvReader->fetchAssoc($headerMap, $remapper);
            }

            foreach ($rows as $row) {
                $this->processRecord($row, $this->columnMap, $result, $preview);
            }
        } catch (\Exception $e) {
            $failedMessage = sprintf("Failed to parse %s", $filepath);
            if (Director::isDev()) {
                $failedMessage = sprintf($failedMessage . " because %s", $e->getMessage());
            }
            print $failedMessage . PHP_EOL;
        } finally {
            ini_set('auto_detect_line_endings', $previousDetectLE);
        }
        return $result;
    }
757340
public static function get($filePath)
    {
        $fileName = basename($filePath);
        if (!array_key_exists($fileName, static::$files)) {
            try {
                $file = new File($filePath);
            } catch (\Exception $e) {
                $file = false;
            }

            static::$files[$fileName] = $file;
        }

        return static::$files[$fileName];
    }
966880
function delete_file($filepath)
	{
		if ( ! $this->_is_conn())
		{
			return false;
		}

		$result = @ftp_delete($this->_conn_id, $filepath);

		if ($result === false)
		{
			if ($this->_debug == true)
			{
				throw new \FtpFileAccessException('Unable to delete');
			}
			return false;
		}

		return true;
	}
886575
public function locate($filePath)
    {
        $file = $filePath;
        if (!is_file($filePath))
        {
            throw new FileException(sprintf('Invalid file! File "%s" does not exist.',
                                            $filePath));
        }

        if (!is_readable($filePath))
        {
            throw new FileException(sprintf('Invalid file! File "%s" is not readable.',
                                            $filePath));
        }

        $pathInfo = pathinfo($filePath);
        if (!isset($pathInfo['extension'])
            || !in_array($pathInfo['extension'], $this->supportedExtensions)
        )
        {
            throw new FileException(sprintf('Invalid file extension! Supported file extensions: %s',
                implode(', ', $this->supportedExtensions)));
        }

        return realpath($file);
    }
1204802
private function loadImageFromFile($filepath)
    {
        $this->from = 'local';
        $this->filename = $filepath;

        if (!is_readable($filepath)) {
            return;
        }

        $image = null;
        $extension = '';
        list($width, $height, $imageType) = getimagesize($filepath);

        switch ($imageType) {
            case IMAGETYPE_GIF:
                $extension = 'gif';
                $image = imagecreatefromgif($filepath);
                break;

            case IMAGETYPE_PNG:
                $extension = 'png';
                $image = imagecreatefrompng($filepath);
                break;

            case IMAGETYPE_JPEG:
                $extension = 'jpg';
                $image = imagecreatefromjpeg($filepath);
                break;
        }

        if ($image) {
            $this->type = $imageType;
            $this->resource = $image;
            $this->extension = $extension;
            $this->width = $this->boxWidth = $width;
            $this->height = $this->boxHeight = $height;
        }
    }
844237
public static function open(string $filepath):\stdClass
    {
        if ($filepath == self::$filepath && self::$file != null) {
            return (self::$file);
        }

        if (!file_exists($filepath)) {
            throw new Server500(new \ArrayObject(array("explain" => "Cannot open file $filepath : File does not exist",
                "solution" => "Please set the correct filepath")));
        }

        if (!is_readable($filepath)) {
            throw new Server500(new \ArrayObject(array("explain" => "Cannot open file $filepath : File not readable",
                "solution" => "Please set the correct permission")));
        }

        $a = json_decode(file_get_contents($filepath));

        self::$file = ($a == null ? new \stdClass() : $a);
        return ($a == null ? new \stdClass() : $a);
    }
702669
protected function getFileContentsArray($filePath)
    {
        $filePath = realpath($filePath);

        static $filecache = array();

        if (isset($filecache[$filePath]) === true) {
            return $filecache[$filePath];
        }

        // Using \SplFixedArray to save some memory, as it can get
        // quire huge, depending on your system. 4mb is nothing here.
        if ($this->fileIsReadable($filePath) === true) {
            return $filecache[$filePath] = \SplFixedArray::fromArray(file($filePath));
        }
        // Not readable!
        return $filecache[$filePath] = new \SplFixedArray(0);
    }
994431
public function open(string $filePath, string $mode)
    {
        $this->exists($filePath, $mode);

        $ptr = @fopen($filePath, $mode);

        if (false === $ptr) {
            throw new FileException("Unable to open $filePath.");
        }

        return $ptr;
    }
1096007
private function getFileExtensionFromFilepath($filepath)
    {
        $fileExtension = pathinfo($filepath, PATHINFO_EXTENSION);

        if (empty($fileExtension)) {
            throw new \Exception('File extension not found');
        }

        return $fileExtension;
    }
802292
private function getFilePath($filePath = null)
    {
        $filePath = $filePath ?? $this->filePath ?? null;

        if (null === $filePath) {
            throw NoFilePathGivenException::import();
        }

        return $filePath;
    }
968570
protected function get_file_content(string $filepath) : String {
        $content = file_get_contents($filepath);
        if ($content === false) {
            throw new \moodle_exception('cannotopenfile', 'error', '', $filepath);
        }
        return $content;
    }
293806
function fileFetchContents( $filePath )
    {
        eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileFetchContents( '$filePath' )", __METHOD__ );

        eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
        $rslt = is_readable( $filePath ) ? file_get_contents( $filePath ) : false;
        eZDebug::accumulatorStop( 'dbfile' );

        return $rslt;
    }
839130
public static function thumbnail($filePath, $previewSize)
    {
        $filePath = normalizePath($filePath);

        if (!is_readable($filePath)) {
            return false;
        }

        $srcFileName = basename($filePath);
        $srcPath = dirname($filePath) . DS;
        $dstPath = normalizePath("{$srcPath}/.tmb/");
        $previewInfo = static::getPreviews($previewSize);
        require_once Plugin::classPath('Field') . 'Lib/class.upload.php';
        $handle = new \upload($srcPath . $srcFileName);

        if (empty($previewInfo)) {
            $previews = static::getPreviews();
            $previewInfo = reset($previews);
        }

        $dstFileNameBody = static::removeExt("{$previewInfo['width']}x{$previewInfo['height']}_{$srcFileName}");
        $dstFilePath = normalizePath("{$dstPath}/{$dstFileNameBody}.jpg");

        if (is_readable($dstFilePath)) {
            return $dstFilePath;
        }

        $handle->image_x = $previewInfo['width'];
        $handle->image_y = $previewInfo['height'];
        $handle->image_resize = true;
        $handle->image_ratio = false;
        $handle->image_ratio_crop = true;
        $handle->image_convert = 'jpg';
        $handle->file_new_name_body = $dstFileNameBody;
        $handle->process($dstPath);

        if (empty($handle->error)) {
            return $handle->file_dst_pathname;
        }

        return false;
    }
1332275
public function readFile($filePath)
    {
        if (false === $fileContent = @file_get_contents($filePath)) {
            throw new RuntimeException(
                sprintf('unable to read file "%s"', $filePath)
            );
        }

        return $fileContent;
    }
331545
public function executeAction($preview = false)
    {
        $jobId = intval($this->getParam(\MUtil_Model::REQUEST_ID));

        $batch = $this->loader->getTaskRunnerBatch('commjob-execute-' . $jobId);
        $batch->setMessageLogFile($this->project->getCronLogfile());
        $batch->minimalStepDurationMs = 3000; // 3 seconds max before sending feedback

        if (!$batch->isLoaded() && !is_null(($jobId))) {
            $batch->addMessage(sprintf(
                    $this->_('Starting single %s mail job %s'),
                    $this->project->getName(),
                    $jobId
                    ));

            // Check for unprocessed tokens
            $tracker = $this->loader->getTracker();
            $tracker->loadCompletedTokensBatch($batch, null, $this->currentUser->getUserId());

            // We could skip this, but a check before starting the batch is better
            $sql = $this->db->select()->from('gems__comm_jobs', array('gcj_id_job'))
                    ->where('gcj_active > 0')
                    ->where('gcj_id_job = ?', $jobId);

            $job = $this->db->fetchOne($sql);

            if (!empty($job)) {
                $batch->addTask('Mail\\ExecuteMailJobTask', $job, null, null, $preview);
            } else {
                $batch->reset();
                $this->addMessage($this->_("Mailjob is inactive and won't be executed"), 'danger');
            }
            
            if ($preview === true) {
                $batch->autoStart = true;
            }
        }

        if ($batch->isFinished()) {
            // Add the messages to the view and forward
            $messages = $batch->getMessages(true);
            if (count($messages)) {
                $this->addMessage($messages, 'info');
            }

            $this->_reroute(array('action'=>'show'));
        }
        
        if ($preview === true) {
            $title = sprintf($this->_('Preview single mail job %s'), $jobId);
        } else {
            $title = sprintf($this->_('Executing single mail job %s'), $jobId);
        }

        $this->_helper->BatchRunner($batch, $title, $this->accesslog);
    }
438940
def get_preview(path)
      resp, body = content_request('/files/get_preview', path: path)
      return FileMetadata.new(resp), body
    end
727565
public static function loadINI($filepath,$prefix_path=null){
    $results = parse_ini_file($filepath,true);
    if($results) {
      $results = static::filterWith(["load.ini", "load"], $results);
      static::loadArray($results,$prefix_path);
    }
  }