php创建文件并作为附件发送,而无需实际创建文件 [英] php create file and send as attachment without actually creating the file

查看:98
本文介绍了php创建文件并作为附件发送,而无需实际创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何读取服务器上的文件并将其附加到PHP中的电子邮件中,但是我想知道是否可以附加由脚本创建但未在服务器上创建的文件(有点像临时文件)文件).

I know how to read a file on the server and attach it to an email in PHP, but I wanted to know if I could attach a file that is created by my script but not created on the server (kinda like a temp file).

因此,请在内存中创建文件并将其附加到电子邮件.

So create file in memory and attach it to email.

奖金:可能还需要创建多个文件,这对于服务器来说是否太多了?我不是说GB,而是说5个文件,每个文件有1000行?

Bonus: might need to create multiple files as well, would this be too much for the server to handle? I'm not talking GB's but like 5 files with 1000 lines each?

推荐答案

是的,只要您使用的任何电子邮件库都支持,就可以做到.如果您不使用它,应该使用它!
不,除非您在1993年购买服务器,否则5个文件对您的服务器来说不会太大.

Yes you can do that, as long as whatever email library you're using supports it. If you're not using one, you should be!
No, 5 files won't be too much for your server unless you bought it in 1993.

希望您的lib不需要文件引用-您可以执行以下操作:

Hopefully your lib won't need a file reference - you can do something like:

$myEmail->attachData('file.name', 'mime/type', $data);

如果确实需要文件路径,则可以使用 php://memory 文件:

If it does need a file path then you could use a php://memory file:

 $f = fopen('php://memory/myfile', 'w');
 fwrite($f, '...');
 fclose($f);

$myEmail->attach('php://memory/myFile');

这篇关于php创建文件并作为附件发送,而无需实际创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆