PHP:是否有可能从文件内容(字符串)创建一个SplFileObject对象? [英] PHP: Is it possible to create a SplFileObject object from file contents (string)?
本文介绍了PHP:是否有可能从文件内容(字符串)创建一个SplFileObject对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
$ contents = file_get_contents(image.png);
是否可以从$ contents创建一个SplFileObject对象?
谢谢!
解决方案
php有一些特殊的流包装器,可以让你重新使用各种文件系统功能
$ contents ='我是一个字符串';
$ file ='php:// memory'; //完整的内存缓冲区
// $ file ='php:// temp / maxmemory:1048576'; //部分内存,如果超过1MB,自动分页到文件
$ o = new SplFileObject($ file,'w +');
$ o-> fwrite($ contents);
您不需要使用 SplFileObject 来使用这些包装器;您可以使用 fopen 和 fwrite 。
For example:
$contents = file_get_contents(image.png);
Is it possible to create a SplFileObject object from $contents?
Thanks!
解决方案
php has some special stream wrappers that let you re purpose the various file system functions
$contents = 'i am a string';
$file = 'php://memory'; //full memory buffer
//$file = 'php://temp/maxmemory:1048576'; //partial memory, automatic paging to file if over 1MB
$o = new SplFileObject($file, 'w+');
$o->fwrite($contents);
You don't need to use SplFileObject to use those wrappers though; you could use fopen and fwrite instead.
这篇关于PHP:是否有可能从文件内容(字符串)创建一个SplFileObject对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文