HTML PHP Form Upload .doc and .docx only [closed]
I need some help with my syntax. I need the possibility to upload either .doc or .docx files. But I dont know how to go about it. Please see my code:
//Сheck that we have a file
if((!empty($_FILES["datafile"])) && ($_FILES['datafile']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 2mb
$filename = basename($_FILES['datafile']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "docx,doc") && ($_FILES["datafile"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") &&
($_FILES["datafile"]["size"] < 2100000)) {
//Determine the path to which we want to save this file
$newname = dirname(__FILE__).'/upload/'.$filename;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['datafile']['tmp_name'],$newname))) {
$sasquach = "The file has been saved as: ".$newname;
$link= 'http://orchardsystems2012.co.za/'.$_SERVER['PATH_INFO'].'/upload/'.$filename;
} else {
//echo "Error: A problem occurre开发者_Go百科d during file upload!";
}
} else {
//echo "Error: File ".$_FILES["datafile"]["name"]." already exists";
}
} else {
//echo "Error: Only .jpg images under 2mb are accepted for upload";
}
} else {
//echo "Error: No file uploaded";
}
Please help :)
.....
if (in_array($ext, array("docx", "doc")
&& (in_array($_FILES["datafile"]["type"], array("application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"))
....
see other types here
精彩评论