我的代码工作正常。邮件也很顺利。但文件没有上传。我认为我的孔代码很好。但我不明白为什么我的代码不起作用。
我的PHP代码
include("config.php");
$NOW_DATE = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$STARTtime = date("U");
// Here we get all the information from the fields sent over by the form.
$cname = $_POST['cname'];
$cmobilenumber = $_POST['cmobilenumber'];
$cemailaddress = $_POST['cemailaddress'];
$ccountry = $_POST['ccountry'];
$cmessage = $_POST['cmessage'];
$allowedExts = array("pdf", "xlsx", "doc", "docx", "ppt");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/ application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["file"]["type"] == "application/pdf"))
&& ($_FILES["file"]["size"] < 200000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 3072) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
$sql = "insert into resume values('','$cname','$cmobilenumber','$cemailaddress','$NOW_TIME','$ccountry','$cmessage')";
$rsd = mysql_query($sql);
$to = 'marvanjaam@gmail.com';
$subject = "Resume";
$message = 'From: '.$cname.' Email: '.$cemailaddress.'Message: '.$cmessage;
$headers = 'From: '.$cemailaddress. "\r\n";
if (filter_var($cemailaddress, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message, $headers); //This method sends the mail.
echo "Your email was successfully sent!";
// success message
}else{
echo " your mail was failed";
};
发送邮件工作正常。但文件没有上传。