上传某些文件时,$ _FILES和$ _POST数据为空 [英] $_FILES and $_POST data empty when uploading certain files

查看:162
本文介绍了上传某些文件时,$ _FILES和$ _POST数据为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,根据我上传的视频,有时整个 $ _ POST $ _ FILES 数组将是空的。这很奇怪,但我在一些视频中发现了它。为了测试我使用的视频都是 video / mp4 文件类型。

 <!DOCTYPE html> 
< html lang =en>
< head>
< meta charset =UTF-8>
< title>文档< / title>
< / head>
< body>
<?php
var_dump($ _ POST);
var_dump($ _ FILES);
?>
< form method =postaction =enctype =multipart / form-data>

< input type =filename =attachment>
< input type =textname =other>
< button type =submitclass =savevalue =保存更改>上传该文件!< / button>
< / form>

< / body>
< / html>

好视频的输出是

<$数组

[other] =>测试字符串

数组

[附件] => Array

[name] => Shasta.mp4
[type] => video / mp4
[tmp_name] => / private / var / tmp / phpAoDLKi
[error] => 0
[size] => 4688949



一个错误的请求会显示以下内容:

 数组




$ $ $ $ $ $ $ $ $ b

我修改了我的php.ini,允许文件上传到50mb的大小,我测试的文件是4.7mb和10.2mb。我完全不知道原因是什么,视频文件名是 Shasta.mp4 (好文件)和 Bulova_Watches.mp4 $ b

如果需要,我可以将文件上传到网站供其他人测试。

post_max_size 设置为 8M 作为您的 php.ini 中的默认值。
当你的文件是 10.4MB 时,会遇到以下错误:


POST内容 - 长度为10237675个字节超过了8388608
个字节的限制在未知中


因为您已经达到限制。
解决这个问题的诀窍是通过改变该值来简单地提高该限制。您可以直接在您的php.ini文件中将其更改为您想要的任何内容,即20M。 您可以通过 .htaccess

  php_value post_max_size 20M 
php_value upload_max_filesize 20M
code>

注意:我还添加了所需的 upload_max_filesize 您需要更大的文件:)

I've noticed that depending on the video I'm uploading that sometimes the entire $_POST and $_FILES array will be empty. This is an odd occurrence but I have found it in a few videos. For the sake of testing the videos I was using are all of video/mp4 file type.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<?php 
    var_dump($_POST);
    var_dump($_FILES);
?>
<form method="post" action="" enctype="multipart/form-data">

    <input type="file" name="attachment">
    <input type="text" name="other">
    <button type="submit" class="save" value="Save Changes">Upload that file!</button>
</form>

</body>
</html>

The output of a good video is

Array
(
    [other] => testing string
)
Array
(
    [attachment] => Array
        (
            [name] => Shasta.mp4
            [type] => video/mp4
            [tmp_name] => /private/var/tmp/phpAoDLKi
            [error] => 0
            [size] => 4688949
        )

)

While a bad request displays the following

Array
(
)
Array
(
)

I've modified my php.ini to allow file uploads to the size of 50mb, the files I'm testing with are 4.7mb and 10.2mb. I'm completely stumped on what the cause is, the video file names are Shasta.mp4 (good file) and Bulova_Watches.mp4 (bad file).

If need be I can upload the files to a site for others to test.

解决方案

The issue you are facing is due to the fact that post_max_size is set to 8M as default in your php.ini. As your file is 10.4MB you run into the following error:

POST Content-Length of 10237675 bytes exceeds the limit of 8388608 bytes in Unknown

Because you've reached that limit. The trick to fixing this is to simply up that limit by changing the value. You could simply change it directly in your php.ini file to whatever you desire, i.e. 20M.

Or you could set it via your .htaccess file with:

php_value post_max_size 20M
php_value upload_max_filesize 20M

Note: I've also added the required upload_max_filesize that you will require for the bigger files :)

这篇关于上传某些文件时,$ _FILES和$ _POST数据为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆