donglan8870 2016-08-02 14:54
浏览 69
已采纳

文件上传中缺少文件类型

I have a page that will allow me to upload a CSV file. Using PHP I then take the contents of the CSV file and insert them into a MySQL database. I've been doing this with no problems for awhile now. Then today, I tried uploading the file and it didn't work. The problem is that there appears to be no file type associated with the CSV file. For example, on a good upload, the debug messages I spit out look like this:

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
            )
)

However, when I upload the problem file with the debug messages on I noticed the file type and file size is empty.

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
        )

)

Anyone have any ideas why the file type is empty? In Windows Explorer, if I hover over either of these files the info balloon over the files say "Type: Microsoft Excel Comma Separated Values File". But there is something wrong with the second file that causes my PHP to puke and not recognize the file type.

  • 写回答

1条回答 默认 最新

  • douzhonglong3789 2016-08-02 15:01
    关注

    The file type is not the problem (I don't think).

    You'll see error code 2 was returned during the attempted file upload in your second example block, and it was NOT written to temporary storage (tmp_name is empty, size is 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
            )
    
    )
    

    Error code 2 is: UPLOAD_ERR_FORM_SIZE: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

    Adjust this value larger in your form HTML.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 angular开发过程中,想要读取模型文件,即图1的335行,会报404错误(如图2)。但我的springboot里配置了静态资源文件,如图3。且在该地址下我有模型文件如图4,请问该问题该如何解决呢?
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常
  • ¥15 Java,消息推送配置