我有一个页面,允许我上传CSV文件.使用PHP我然后获取CSV文件的内容并将它们插入MySQL数据库.我现在一直没有遇到任何问题.然后今天,我尝试上传文件,但它没有用.问题是似乎没有与CSV文件关联的文件类型.例如,在良好的上传中,我吐出的调试消息如下所示:
You uploaded a file: buylist_235.csv
file type: application/vnd.ms-excel
file size: 10456
File is valid, and was successfully uploaded. Here is some more debugging info:Array (
[csv] => Array
(
[name] => buylist_235.csv
[type] => application/vnd.ms-excel
[tmp_name] => C:\xampp\tmp\php3C1E.tmp
[error] => 0
[size] => 10456
)
)
Run Code Online (Sandbox Code Playgroud)
但是,当我上传带有调试消息的问题文件时,我注意到文件类型和文件大小为空.
You uploaded a file: buylist_235_1.csv
file type:
file size: 0
Possible file upload attack!
Here is some more debugging info:Array
(
[csv] => Array
(
[name] => buylist_235_1.csv
[type] =>
[tmp_name] =>
[error] => 2
[size] => 0
)
)
Run Code Online (Sandbox Code Playgroud)
任何人都有任何想法为什么文件类型为空?在Windows资源管理器中,如果我将鼠标悬停在这些文件中的任何一个上,则文件上的信息气球会显示"类型:Microsoft Excel逗号分隔值文件".但第二个文件有问题导致我的PHP呕吐而无法识别文件类型.
文件类型不是问题(我不认为).
你会看到error代码2在你的第二个例子块试图文件上传过程中返回,并没有写入临时存储(tmp_name是空的,size为0).
You uploaded a file: buylist_235_1.csv
file type:
file size: 0
Possible file upload attack!
Here is some more debugging info:Array
(
[csv] => Array
(
[name] => buylist_235_1.csv
[type] =>
[tmp_name] =>
[error] => 2
[size] => 0
)
)
Run Code Online (Sandbox Code Playgroud)
错误代码2是:UPLOAD_ERR_FORM_SIZE:上传的文件超出了HTML表单中指定的MAX_FILE_SIZE指令.
在表单HTML中调整此值.