简体   繁体   English

在php中上传rtf文件

[英]Uploading rtf file in php

I can upload other file without error.我可以上传其他文件而不会出错。 But whenever I tried to upload rtf file in php it fails.但是每当我尝试在 php 中上传 rtf 文件时,它都会失败。 My code it below:我的代码如下:

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

HTML form: HTML表单:

<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 $max = 62914560 字节

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 PHP 警告:24783980 字节的 POST Content-Length 超出第 0 行未知中 8388608 字节的限制

I upload the same file (resaved as doc format using msword) without problem.我上传相同的文件(使用 msword 重新保存为 doc 格式)没有问题。 But when it comes to rtf it fails.但是当涉及到 rtf 时,它失败了。 I can upload other files like doc, docx, xls, xlsx, pdf, txt and all image files without problem.我可以毫无问题地上传其他文件,如 doc、docx、xls、xlsx、pdf、txt 和所有图像文件。 What could be the problem.可能是什么问题呢。 I am using php 7.1.19 Thanks我正在使用 php 7.1.19 谢谢

  1. Check if your HTML form has enctype="multipart/form-data".检查您的 HTML 表单是否具有 enctype="multipart/form-data"。

  2. If your file input tag name is "uploadname".如果您的文件输入标签名称是“uploadname”。

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. MAX_FILE_SIZE 隐藏字段(以字节为单位)必须位于文件输入字段之前,其值为 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.然而,最大尺寸的 PHP 设置(在服务器端)是不能被愚弄的。

… and it looks like your server-side configuration is set to a lower value anyway, so you need to increase that. ...而且看起来您的服务器端配置无论如何都设置为较低的值,因此您需要增加该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM