I'm having trouble with reading and writing the php://temp
stream in PHP 5.3.2
I basically have:
file_put_contents('php://temp/test', 'test'); var_dump(file_get_contents('php://temp/test'));
The only output I get is string(0) ""
Shouldn't I get my 'test' back?
php://temp
is not a file path, it's a pseudo protocol that always creates a new random temp file when used. The /test
is actually being ignored entirely. The only extra "arguments" the php://temp
wrapper accepts is /maxmemory:n
. You need to keep a file handle around to the opened temp stream, or it will be discarded:
$tmp = fopen('php://temp', 'r+'); fwrite($tmp, 'test'); rewind($tmp); fpassthru($tmp); fclose($tmp);
See http://php.net/manual/en/wrappers.php.php#refsect1-wrappers.php-examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With