上传.txt扩展文件和.doc扩展文件时出现错误 [英] I am getting error while upload the .txt extension file and .doc extension files
本文介绍了上传.txt扩展文件和.doc扩展文件时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为老师制作一个网络表格,学生可以在那里提交作业,老师可以检查.但是我遇到错误,我无法上载.txt和.doc,我在自己的代码中使用了探针,这是我的努力.
I am making a web form for teachers where student can submit there assignment and teacher can check. but i am getting error i can not upload the .txt and .doc i am having probelm in my code here is my effort.
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";
}
}
}
}
推荐答案
您的代码中有一些小错误,即您输入了错误的扩展名.
You have minor mistake in your code that you have put wrong extension.
if((($_FILES['file']['type']=="text/plain") || ($_FILES['file']['type']=="application/msword"))&&($_FILES['file']['size']>"0"))
它不是.txt和.doc,它是文本文件的文本/纯文本,而对于.doc,它是 application/msword . 我希望它能起作用.
It is not .txt and .doc it is text/plain for text files and for .doc it is application/msword. I hope it will work.
这篇关于上传.txt扩展文件和.doc扩展文件时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文