我在读写PHP 5.3.2中的php://temp
流时遇到麻烦
我基本上有:
file_put_contents('php://temp/test', 'test');
var_dump(file_get_contents('php://temp/test'));
我得到的唯一输出是string(0) ""
我不应该把我的“测试”回来吗?
/test
被完全忽略。 php://temp
包装器接受的唯一额外“参数”是/maxmemory:n
。您需要保留打开的临时流的文件句柄,否则它将被丢弃:$tmp = fopen('php://temp', 'r+');
fwrite($tmp, 'test');
rewind($tmp);
fpassthru($tmp);
fclose($tmp);
请参见http://php.net/manual/en/wrappers.php.php#refsect1-wrappers.php-examples
$handle = fopen('php://temp', 'w+');
fwrite($handle, 'I am freaking awesome');
fread($handle); // returns '';
rewind($handle); // resets the position of pointer
fread($handle, fstat($handle)['size']); // I am freaking awesome
php:// memory和php:// temp不可重用,即在流之后已关闭,无法再次引用它们。
file_put_contents('php://memory', 'PHP');
echo file_get_contents('php://memory'); // prints nothing
我想这意味着file_put_contents()
在内部关闭流,这使file_get_contents()
无法再次恢复流中的数据