开发者

HTML PHP Form Upload .doc and .docx only [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜