duan19805 2018-08-18 10:56
浏览 80
已采纳

在php上传rtf文件

I can upload other file without error. But whenever I tried to upload rtf file in php it fails. My code it below:

if(isset($_POST['pid'])){           
    if($_FILES['uploadname']['name']==''){
     //Failed
    }else{
    //upload the file
    }
}

HTML form:

<form method="post" enctype="multipart/form-data">
  <input type="file" accept=".csv,.doc,.pdf,.docx,.xls,.xlsx,.rtf,.txt, image/*" 
        name="uploadname" style="width:100%;">
   <input type="hidden" name="pid" value="<?php echo $id; ?>">
   <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
</form>

$max = 62914560 bytes

I got undefined index uploadname

The server log:

PHP Warning: POST Content-Length of 24783980 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

I upload the same file (resaved as doc format using msword) without problem. But when it comes to rtf it fails. I can upload other files like doc, docx, xls, xlsx, pdf, txt and all image files without problem. What could be the problem. I am using php 7.1.19 Thanks

  • 写回答

2条回答 默认 最新

  • doumaqing6652 2018-08-18 11:51
    关注

    See the documentation:

    The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted by PHP. This form element should always be used as it saves users the trouble of waiting for a big file being transferred only to find that it was too large and the transfer failed. Keep in mind: fooling this setting on the browser side is quite easy, so never rely on files with a greater size being blocked by this feature. It is merely a convenience feature for users on the client side of the application.

    You put that field after the file input, so it will be ignored.

    The PHP settings (on the server side) for maximum-size, however, cannot be fooled.

    … and it looks like your server-side configuration is set to a lower value anyway, so you need to increase that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度