file_put_contents(超过 1 个文件)

file_put_contents (more than 1 file)

当前代码:

public function downloadInvoicesFromServer($invoices=array())
{
    foreach ($invoices as $invoice)
    {
        if ($stream = fopen($invoice, 'r')) 
        {
            file_put_contents(PATH . '/invoices/' . rand() . '.pdf', $stream);
            fclose($stream);
        }
    }
}

包括 3 个文件。 PHP returns 我这 3 个包含的文件,但只有最后一个有内容的文件。前 2 个文件是空的。

我不知道我做错了什么。有人能帮帮我吗?

最终结果: 2 个(或更多)文件上传到我的服务器并作为附件(当然带有原始内容)通过电子邮件发送。

问题: 只有最后一个文件具有其原始内容。所有其他文件其内容(无论有多少文件)都是空的。

trim() 函数有效。谢谢大家的回复!实际代码有效,但似乎 PHP_EOL explode (shift enter in text area) 需要 trim().