rdl*_*rey 20
为了避免使用磁盘上的实际文件进行写 - 读 - 删除循环,我会使用php的内置php://temp和php://memory IO流包装器文档将所有临时"文件"数据保存在内存中.
// open a temporary file handle in memory
$tmp_handle = fopen('php://temp', 'r+');
fwrite($tmp_handle, 'my awesome text to be emailed');
// do some more stuff, then when you want the contents of your "file"
rewind($tmp_handle);
$file_contents = stream_get_contents($tmp_handle);
// clean up your temporary storage handle
fclose($tmp_handle);
Run Code Online (Sandbox Code Playgroud)
您永远不必将文件写入或删除到磁盘.另外,请注意使用php://temp和php://memory来自主题的文档之间的区别:
php:// memory和php:// temp是读写流,允许临时数据存储在类似文件的包装器中.两者之间的唯一区别是php://内存将始终将其数据存储在内存中,而一旦存储的数据量达到预定义的限制(默认值为2 MB),php:// temp将使用临时文件.此临时文件的位置以与sys_get_temp_dir()函数相同的方式确定.