【发布时间】:2011-10-18 03:13:51
【问题描述】:
我需要一些语法方面的帮助。我需要上传 .doc 或 .docx 文件的可能性。但我不知道该怎么做。请看我的代码:
//С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 occurred 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";
}
请帮忙:)
【问题讨论】:
标签: html forms file file-upload