繁体   English   中英

从php发送电子邮件附件并上传ftp

[英]Send email attachment from php and upload ftp

在这里,我可以将接收到的文件(文件名称未知,它是用当前日期和时间创建的)上传到FTP。 而且我想以同样的方式将该附件作为邮件发送。

我得到的错误是(来自下面代码的最后一条语句):

文件打开错误。

发送邮件时,我无法选择接收到php中的文件。 有人可以告诉我原因和方式吗?

$destDir = 'myweb.net/name/' .$dir;
 $workDir = 'tmpfiles';// define this as per local system

 // get temporary file name for the uploaded file
$tmpName = basename($_FILES['uploadedfile']['tmp_name']);
$fileName = basename($_FILES['uploadedfile']['name']);

// copy uploaded file into current directory
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$workDir."/".$tmpName)
 or die("Cannot move uploaded file to working directory");

// open connection
$conn = ftp_connect($ftp_server) or die ("Cannot initiate connection to host");

// send access parameters
ftp_login($conn, 'abcd', 'saddad') or die("Cannot login");

// perform file upload
$upload = ftp_put($conn, $destDir."/".$_FILES['uploadedfile']['name'],$workDir."/".$tmpName, FTP_BINARY);

// check upload status
// display message
if (!$upload) {
 echo "Cannot upload<br />\n";
} else {


 $to = $Remail;
 $subject = "This is subject";
 $message = "This is test message.";
// Open a file
 $file = fopen($_FILES['uploadedfile']['name'], "r" );
 if( $file == false )
  {
 echo "Error in opening file";
 exit();
 }

您正在尝试打开原始客户端文件名,该文件名与服务器上的任何文件都没有任何关系。 服务器上存在的唯一文件是['tmp_name']列出的文件,您现在将其移至$workdir

你的打开时间应该是

$file = fopen($workDir . '/' . $tmpName, 'r');

另外,您对用户->网络服务器上载的东西绝对没有错误处理,只需假设上载永远不会失败。 错误的假设。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM