php保存临时本地文件,php – 将文件写入临时位置

为了避免使用磁盘上的实际文件进行写 – 读 – 删除循环,我会使用php的内置php:// temp和php:// memory

IO stream wrappersdocs将所有临时“文件”数据保存在内存中.

// 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);

您永远不必将文件写入或删除到磁盘.另外,请注意使用php:// temp和php://来自主题文档的内存之间的区别:

php://memory and php://temp are read-write streams that allow temporary data to be stored in a file-like wrapper. The only difference between the two is that php://memory will always store its data in memory, whereas php://temp will use a temporary file once the amount of data stored hits a predefined limit (the default is 2 MB). The location of this temporary file is determined in the same way as the sys_get_temp_dir() function.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值