Reputation:
Is there a way that I can access a file from a phar without having to save the phar to disk first? In the following code, $fileContentsString
is the contents of a phar file that was loaded from the network. How can I take that string and read a file from it without having to save the string to disk as a file first? I've tried writing the string to php://temp
and then using Phar::loadPhar
to read it, but that fails.
$tmpFilePath = TMP_PATH . '/' . $filename;
// Save the file to TMP_PATH
$fp = fopen($tmpFilePath, 'w');
fwrite($fp, $fileContentsString);
fclose($fp);
$contents = file_get_contents('phar://' . $tmpFilePath . '/json.txt');
Upvotes: 2
Views: 448
Reputation: 31078
php://temp
is a stream that can be used to store data in memory - but it can be only used via a file handle, not as a file system.
Opening another file handle on php://temp
will give you another part of the memory, and thus a new "file".
You need a memory-only file system like PEAR's Stream_Var package which lets you access variables as a file system.
Upvotes: 1