如果文件上传成功,请尝试让我的脚本向我发送电子邮件。以下是我将脚本文件作为username.site.zip保存到服务器的部分:
if ($this->file->save($uploadDirectory . $_SESSION['myusername'] . '.site.' . $ext)){
return array('success'=>true);}
else {
return array('error'=> 'Could not save uploaded file.' .
'The upload was cancelled, or server error encountered');
}
我不太确定如何添加邮件功能,以便如果成功=> true则会发送邮件('email @ domain.com','subject','body');
任何帮助都会很棒。
答案 0 :(得分:0)
在返回success=>true
数组之前插入邮件命令,如下所示:
if ($this->file->save($uploadDirectory . $_SESSION['myusername'] . '.site.' . $ext)){
mail('email@domain.com','subject','body');
return array('success'=>true);}
else {
return array('error'=> 'Could not save uploaded file.' .
'The upload was cancelled, or server error encountered');
}
也许将它封装在try-catch块中,但这应该可以直接使用。
答案 1 :(得分:0)
<?php
if ($this->file->save($uploadDirectory . $_SESSION['myusername'] . '.site.' . $ext)){
$message = "The file was successfully uploaded.";
mail('email@domain.com', 'My Subject', $message);
return array('success'=>true);
} else {
return array('error'=> 'Could not save uploaded file.' .
'The upload was cancelled, or server error encountered');
}
?>
你拥有它。不确定你还需要什么。