Current code:
public function downloadInvoicesFromServer($invoices=array())
{
foreach ($invoices as $invoice)
{
if ($stream = fopen($invoice, 'r'))
{
file_put_contents(PATH . '/invoices/' . rand() . '.pdf', $stream);
fclose($stream);
}
}
}
Included are 3 files. PHP returns me those 3 included files, but only the last file with content. The first 2 files are empty.
I've got no clue what I'm doing wrong. Does anyone could help me?
End result: 2 (or more) files are uploaded on my server and are sent as attachments (with original content, of course) in an e-mail.
Issue: Only the last file has its original content. All other files its content (no matter how many files) are empty.