我一直致力于一个用户在其他用户个人资料页面上传图片的项目。我也成功上传和发送电子邮件,但如果一次上传中有多个文件,它会发送多封电子邮件。
$sendmail = true;
if(!empty($_FILES)){
$team_id = $_GET['param1'];
$user_id = $_GET['param2'];
$id = $_GET['param3'];
$sql = "SELECT * FROM team where team_id = '$team_id'" ;
$sql_result = mysqli_query($conn,$sql) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysqli_fetch_assoc($sql_result)){
$abcd = $row;
}
$targetDir = "../user_images/";
$fileName = $_FILES['file']['name'];
$fileNamex = substr($fileName, -3);
$fileName = rand(1000,100000).md5($fileName).'_'.$fileName;
$targetFile = $targetDir.$fileName;
if( move_uploaded_file( $_FILES['file']['tmp_name'] , $targetFile ) ){
mysqli_query($conn, "INSERT INTO gallery (team_id , user_id , id , userPic, token) VALUES('$team_id','$user_id','$id','$fileName','0')") or die(mysqli_error($conn));
if($sendmail === true){
$htmlContent = file_get_contents ("../email_template_header.php");
$registerURL = $siteURL.'/register/';
if($abcd['claimed'] == '1'){
$htmlContent .= "New image(s) has been uploaded to your business. Please <a href='$registerURL'>login</a> and approve them";
}
else{
$htmlContent .= "New image(s) has been uploaded to your business. Please <a href='$registerURL'>register</a> to claim your business";
}
$htmlContent .= file_get_contents ("../email_template_footer.php");
$to = $abcd['b_email'];
require '../PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->setFrom('mail@abc.com', 'ABC');
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = 'New Image Uploaded';
$mail->Body = $htmlContent;
$mail->send();
$mail->clearAddresses();
$sendmail = false;
}
}
}
这不起作用,因为每个文件都运行完整的代码,http://www.dropzonejs.com/上的默认示例中也没有循环,所以我可以在索引标志的帮助下检查文件是否有已上传或未上传。任何帮助表示赞赏。
由于
答案 0 :(得分:1)
Dropzone.options.filedrop = {
init: function () {
this.on("complete", function (file) {
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
doSomething();
}
});
}
};