使用SwiftMailer和PHP检索要附加到电子邮件的文件名
我昨天问了这个问题并得到了一个建议并使用了它,但由于某种原因它没有用.
因此,我需要检索用户从 HTML表单上传到我的服务器的文件的名称.我需要将此文件附加到由 PHP / SwiftMailer发送的电子邮件中. 这是我的代码,文件上传部分: //File upload // Where the file is going to be placed $target_path = "uploads/"; // Add the original filename to our target path. //Result is "uploads/filename.extension" $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file,please try again!"; } //End of file upload 这是文件附加部分: //Create the attachment $attachment = Swift_Attachment::fromPath($_FILES['uploadedfile']['tmp_name']); 为什么不从服务器获取文件?
谢谢! 解决方法
使用:
$attachment = Swift_Attachment::fromPath($target_path); 这是因为您已将文件从其临时位置移动,$_FILES [‘uploadedfile’] [‘tmp_name’]返回使用move_uploaded_file移动文件之前的路径.这假设$target_path在swift邮件程序代码的范围内 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |