PHP:是否可以从文件内容(字符串)创建SplFileObject对象?

时间:2013-07-13 02:56:44

标签: php file object

例如:

$contents = file_get_contents(image.png);

是否可以从$ contents?

创建SplFileObject对象

谢谢!

1 个答案:

答案 0 :(得分:10)

php有一些special stream wrappers可以让您重新使用各种文件系统函数

$contents = 'i am a string';
$file = 'php://memory'; //full memory buffering mode
//$file = 'php://temp/maxmemory:1048576'; //partial memory buffering mode. Tries to use memory, but over 1MB will automatically page the excess to a file.
$o = new SplFileObject($file, 'w+');
$o->fwrite($contents);

您不需要使用SplFileObject来使用这些包装器;您可以改用fopenfwrite