我有一个代码在两个不同的文件夹中上传两个文件(图像和文本)。
$file_path = "users/".$uname."/dp/";
$file_path2 = "users/".$uname."/resume/";
$q=mkdir("users/".$uname."/dp/", 0777, $recursive=true);
$r=mkdir("users/".$uname."/resume/", 0777, $recursive=true);
if($q && $r)
{
$targate = $file_path.basename($_FILES['dp']['name']);
//echo $targate ;die;
if ((($_FILES['dp']["type"] == "image/gif") || ($_FILES['dp']["type"] == "image/jpeg") || ($_FILES['dp']["type"] == "image/png") ||
($_FILES['dp']["type"] == "image/jpg")) && ($_FILES['dp']["size"] < 20000))
{
if ($_FILES['dp']["error"] > 0)
{
echo "Return Code: " . $_FILES['dp']["error"] . " ";
}
else
{
move_uploaded_file($_FILES['dp']["tmp_name"], $targate);
}
}
else
{
//echo "Invalid file";
}
$targate2 = $file_path2.basename($_FILES['resume']['name']);
//echo $targate2 ;die;
if ((($_FILES["resume"]["type"] == "text/plain") || ($_FILES["resume"]["type"] == "application/msword")
|| ($_FILES["resume"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")) && $_FILES['resume']["size"] < 20000)
{
if ($_FILES['resume']["error"] > 0)
{
echo "Return Code: " . $_FILES['resume']["error"] . " ";
}
else
{
move_uploaded_file($_FILES['resume']["tmp_name"], $targate2);
}
}
else
{
//echo "Invalid file";
}
echo "success";die;
}
else{ echo "fail";die;}
对于所有类型的图像,它都可以正常工作。但如果是文本文件(doc 和 docx 文件),它会打印成功,但只上传图像文件。
当我更换这个
if ((($_FILES["resume"]["type"] == "text/plain")
|| ($_FILES["resume"]["type"] == "application/msword")
|| ($_FILES["resume"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")) && $_FILES['resume']["size"] < 20000)
条件与
if (($_FILES["resume"]["type"] == "text/plain")
&& $_FILES['resume']["size"] < 20000)
这适用于.txt 有什么问题?我在哪里做错了?