Swift 4.0 attachment path
Posted: Tue Mar 10, 2009 6:50 pm
In SwiftMail 3 to send attachment the following example works
if(!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: ?p=emailFailure&error=upload_failed");
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach( new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
In SwiftMail 4.0 how is this accomplished?
When just using:
$message->attach(Swift_Attachment::fromPath($file_path.'/'.$file_name, $file_type));
it does not work
if(!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: ?p=emailFailure&error=upload_failed");
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach( new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
In SwiftMail 4.0 how is this accomplished?
When just using:
$message->attach(Swift_Attachment::fromPath($file_path.'/'.$file_name, $file_type));
it does not work