File reader for attachments

@param string $path filepath of the attachment

@return string binary representation of file, base64'd
482779
protected function buildAttachmentContent($path)
    {
        if (!file_exists($path)) {
            $this->logger->error("Could not find file {$path} for attaching to Archangel mail.");
            return '';
        }

        $handle = fopen($path, 'r');
        $contents = fread($handle, filesize($path));
        fclose($handle);

        $contents = base64_encode($contents);
        $contents = chunk_split($contents);
        return $contents;
    }
863109
protected function _getContents($path) {
		$contents = '';
		if (($fp = $this->_fopen($path))) {
			while (!feof($fp)) {
			  $contents .= fread($fp, 8192);
			}
			$this->_fclose($fp, $path);
			return $contents;
		}
		return false;
	}
370075
public function getFile($path)
    {
        $file = new File($this->getFileSystemId(), $this->getFullPath($path));
        $file->setServiceLocator($this->getServiceLocator());
        return $file;
    }
739484
public static function getTypeFromFile(string $path): string
    {
        if (!is_file($path) || !is_readable($path)) {
            throw new \InvalidArgumentException(
                "invalid value provided for 'path'; ".
                "expecting an absolute path to a readable file"
            );
        }

        $finfo = new \finfo(FILEINFO_MIME_TYPE);
        $type = @$finfo->file($path);
        return ($type === false) ? "application/octet-stream" : $type;
    }
1313327
public function read($path)
    {
        list (, $fileId) = $this->splitPath($path);
        if ($response = $this->service->files->get($fileId, $this->applyDefaultParams([
            'alt' => 'media'
        ], 'files.get'))) {
            return [
                'contents' => (string) $response->getBody()
            ];
        }

        return false;
    }
344909
protected function basePath(string $path): string
    {
        // This set of preg_match would filter ftp' user is not accessing
        // exact path as path('public'), in most shared hosting ftp' user
        // would only gain access to it's /home/username directory.
        if (\preg_match('/^\/(home)\/([a-zA-Z0-9]+)\/(.*)$/', $path, $matches)) {
            $path = '/'.\ltrim($matches[3], '/');
        }

        return $path;
    }
295494
public static function readAndDelete($path)
    {
        $path = self::normalizePath($path);
        $contents = file_get_contents($path);
        if ($contents === false) {
            return false;
        }
        self::removeFile($path);
        return $contents;
    }
710353
public static function getFileBaseNameWithoutExt($path)
    {
        $baseName = pathinfo($path,PATHINFO_BASENAME);
        $extName= self::getFileExtName($path);
        $pos=strrpos($baseName, $extName);
        if($pos>0){
            $baseName=substr($baseName, 0,$pos-1);
        }
        return $baseName;
    }
126593
public function file($path)
    {
        try {
            $contents = $this->filesystem->read($this->localPath."/{$path}");

            return preg_split("/\r\n|\n|\r/", $contents);
        } catch (Flysystem\FileNotFoundException $e) {
            throw new CompilerException($e->getMessage(), null, $e->getCode(), $e);
        }
    }
1130600
public function read(string $path): string
    {
        $location = $this->applyBasePath($path);
        $content  = file_get_contents($location);

        unset($location);

        return $content;
    }
638005
protected function getFileInformation($path) {
    $file = pathinfo($path);

    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mimetype = finfo_file($finfo, $path);
    // Check if mimetype is supported.
    if (!in_array($mimetype, $this->valid_mimes)) {
      if ($mimetype == 'text/plain') {
        $mimetype = 'application/octet-stream';
      }
      else {
        $this->triggerError('Unsupported mime type: ' . $mimetype);
      }
    }

    $contents = file_get_contents($path);

    return [
      'name'      => str_replace(' ', '-', $file['filename']),
      'filename'  => $file['basename'],
      'extension' => $file['extension'],
      'mimetype'  => $mimetype,
      'contents'  => $contents,
      'size'      => strlen($contents)
    ];
  }
1003941
public function read($path)
    {
        $path = $this->applyPathPrefix($path);

        $object = $this->bucket->object($path);

        $contents = $object->downloadAsString();

        return compact('path', 'contents');
    }
1020809
public function getFile($path = '')
    {
        $response = $this->sendRequest('GET', $path);

        $result = [];
        foreach ($response->getHeaders() as $key => $value) {
            $result['headers'][strtolower($key)] = $value[0];
        }
        $result['body'] = $response->getBody();
        return $result;
    }
1060200
protected function readlink($path) {
		if (!($target = @readlink($path))) {
			return false;
		}
		
		if (substr($target, 0, 1) != DIRECTORY_SEPARATOR) {
			$target = dirname($path).DIRECTORY_SEPARATOR.$target;
		}
		
		if ($this->_inpath($target, $this->aroot)) {
			$atarget = realpath($target);
			return $this->_normpath($this->root.DIRECTORY_SEPARATOR.substr($atarget, strlen($this->aroot)+1));
		}

		return false;
	}
1314925
private static function getMimeTypeOfFile($path)
    {
        $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime     = finfo_file($fileInfo, $path);
        finfo_close($fileInfo);

        return $mime;
    }
569507
public static function mime($path)
    {
        $mime = false;

        if (is_readable($path)) {
            if (function_exists('finfo_open')) {
                $buffer = file_get_contents($path, false, null, -1, 5012);

                $finfo = finfo_open(FILEINFO_MIME_TYPE);
                $mime = finfo_buffer($finfo, $buffer);
                finfo_close($finfo);

                $buffer = null;
            } elseif (function_exists('mime_content_type')) {
                $mime = mime_content_type($path);
            }
        }

        if ($mime !== false && strpos($mime, 'application/') === 0) {
            $size = filesize($path);
            $mime = $size >= 0 && $size < 2 ? 'text/plain' : $mime;
        }

        return $mime;
    }
386437
public function findTranslationsFilesByPaths(string $path) : Finder
    {
        $finder = new Finder();
        $finder
            ->files()
            ->in($path)
            ->name('*.php');

        return $finder;
    }