PHP下载代码无效

时间:2011-05-07 02:23:34

标签: php download

有人可以告诉我为什么这段代码无效。我希望用户在提交用户数据后下载文件“tokina.pdf”,如果任何字段为空,页面会重定向到登录页面。但即使用户数据不正确,代码也始终会启动下载过程。

谢谢

<?php


$name = $_POST["name_first"];

$mail = $_POST['email'];    

$number = $_POST['phone_number'];

echo "Name : $name";       
echo '<br>';    
echo "Email-ID : $mail";     
echo '<br>';    
echo "Phone-Number : $number";       
$email_message = "first name: {$name} email is {$mail} number is {$number} ";     
mail('vinferrari@gmail.com', 'Form Response', $email_message);        
if ($mail == "" && $name == "" && $number == "")      
{

header('Location: m1.php'); (redirect to page where user data is collected)
echo "error in submitted data";      
}    
else
{  

//download.php  

//content type  

header('Content-type: application/pdf');         

//open/save dialog box  


header('Content-Disposition: attachment; filename="tokina.pdf"');        

//read from server and write to buffer  

readfile('tokina.pdf');         

}





?>

1 个答案:

答案 0 :(得分:4)

  

如果任何字段为空

所以它不是AND而是OR

if ($mail == "" && $name == "" && $number == "")

应该

if ($mail == "" OR $name == "" OR $number == "")