Trying to save an attachment from email into my server, the script I have so far works fine however, it saves the file in my wp root folder.
foreach ($attachments as $key => $attachment) {
$name = $attachment['name'];
$contents = $attachment['attachment'];
file_put_contents($name, $contents);
}
How can I save the file into a different folder?
trying with this code but not working.
foreach ($attachments as $key => $attachment) {
$name = $attachment['name'];
$contents = $attachment['attachment'];
file_put_contents(get_stylesheet_directory_uri() . '/email_attachments/' . $name, $contents);
}
Any Idea?