2013-03-28 39 views
0

我使用下面的腳本來驗證上傳的文件是否爲pdf,以及它是否與phpmailer一起發送。它發送電子郵件,但沒有附件。此外,它還允許我附加非PDF文件。請幫忙。fileinfo不僅限於pdf

ob_start(); 
require("class.phpmailer.php"); 

if(isset($_FILES['upload']['tmp_name'])){ 
$finfo = finfo_open(FILEINFO_MIME_TYPE); 
$mime=finfo_file($finfo, $_FILES['upload']['tmp_name']); 
if($mime=='application/pdf'){ 

$message = "some message"; 
$mail = new PHPMailer(); 
$mail->From  = ('[email protected]'); 
$mail->AddAddress=('[email protected]'); 
$mail->Subject = "Submitted files"; 
$mail->Body  = $message; 
$mail->WordWrap = 50; 

foreach($_FILES['upload']['tmp_name'] as $upload) 
if(!empty($upload)) { 
$mail->AddAttachment($upload); 
} 
$mail->Send(); 

header("Location: thankyou.php"); 
exit();  
}} 
+0

的腳本,是不會做的,因爲語法錯誤的東西。 – VolkerK 2013-03-28 08:18:01

+0

@VolkerK我已經更新了我的腳本作爲建議,但現在我不再收到該電子郵件了,即使在附加pdf文件時也是如此。請幫忙。謝謝。 – 2013-03-31 22:58:58

+0

XDebug + netbeans是一個易於安裝PHP的調試/前端組合,可以幫助您指出問題:https://netbeans.org/kb/docs/php/debugging.html – VolkerK 2013-04-02 07:03:31

回答

0

目前您有:

if(...) { 
    ... 
    if($mime=='application/pdf') { 
    } 
} 
// some code you want to be executed 
// only if the mime type is application/pdf 

但是你想:

if (...) { 
    .. 
    if ($mime=='application/pdf') { 
     // place the code you want to be executed 
     // only if the mime type is application/pdf 
     // here - before the closing } 
    } 
}