我正在为老师制作一个网络表格,学生可以在那里提交作业,老师可以检查。但我收到错误,我无法上传 .txt 和 .doc 我的代码中有问题,这是我的努力。
error_reporting(E_ALL ^ E_NOTICE);
if ($_POST["upload"] == "1") {
if ((($_FILES['file']['type'] == ".txt") || ($_FILES['file']['type'] == ".doc")) && ($_FILES['file']['size'] > "0")) {
$id = 4881;
$name = "Naeem";
/*first image folder i i showed abd get file and move*/
$fileName = $_FILES["file"]["name"];
$fileName = preg_replace('#[^a-z.0-9]#i', '', $fileName);
$kaboom = explode(".", $fileName);
// Split file name into an array using the dot
$fileExt = end($kaboom);
// Now target the last array element to get the file extension
$fileName = $id . "(" . time() . rand() . ")." . $fileExt;
$to = "file/" . $fileName;
/*this step is used to move file from tmp to a folder*/
if (move_uploaded_file($_FILES['file']['tmp_name'], $to)) {
if ($query = mysql_query("INSERT INTO `file` (
`id` ,
`std_id` ,
`std_name` ,
`file_url`
)
VALUES (
NULL , '" . $id . "', '" . $name . "', '" . $to . "'
);"))
{
echo "Uploaded succesfully";
}
}
}
}