Created
September 22, 2020 10:06
-
-
Save putzflorian/e8a187d6e7bf66cfc52fc18ec3e6d62f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @return resource | |
*/ | |
public function getStream() | |
{ | |
if ($this->stream) { | |
if(get_resource_type($this->stream) != "stream"){ | |
$this->stream = null; | |
}else{ | |
$streamMeta = stream_get_meta_data($this->stream); | |
if (!@rewind($this->stream) && $streamMeta['stream_type'] === 'STDIO') { | |
$this->stream = null; | |
} | |
} | |
} | |
if (!$this->stream && $this->getType() != 'folder') { | |
if (file_exists($this->getFileSystemPath())) { | |
$this->stream = fopen($this->getFileSystemPath(), 'r', false, File::getContext()); | |
} else { | |
$this->stream = tmpfile(); | |
} | |
} | |
return $this->stream; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment