添加新的输入类型“文件”后,$ _POST变空。 [英] $_POST goes empty after adding a new input type "file"

查看:138
本文介绍了添加新的输入类型“文件”后,$ _POST变空。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个脚本,wish是一个简单的表单,通过POST发送文件。第二个文件,处理信息。

默认情况下,我给用户一些字段,其中之一是一个类型为file的输入字段,还有,几个隐藏的,这给了我值在POST上工作。

我发现,当添加一个新的输入类型文件,$ _POST返回数组0,即使$ _FILES也不返回任何内容。我不知道如何解决这个问题,它保持默认的输入框类型文件时工作得很好。

  < form id =formularioenctype =multipart / form-dataaction =projectos_processar.phpmethod =POST> 

Modo inserir projecto item!< br />< br />
< label> Imagem de apresentacao:< / label>


< br />
< br />

< input type =fileid =videoname =videoclass =validate ['required','video']cols =100>

< br />
< br />
< hr>
公证项目? <峰; br />
< br />
< br />

Sim< input type =radioname =publishedvalue =1>< br>
Nao< input type =radioname =publishedvalue =0checked =true>< br>

< hr>

<! - INICIO :: CAMPOS EM MODO HIDDEN - >
< input type =hiddenvalue =centername =crop_X_Y/>
< input type =hiddenvalue =assets / publicidade / FURIOUS01 /name =stringDirPagina/>
< input type =hiddenvalue =128name =parent_id/>
< input type =hiddenvalue =projectos_itemname =pagina_id/>
< input type =hiddenvalue =inserirname =tarefa/>
<! - FIM :: CAMPOS EM MODO HIDDEN - >

< br />
< input type =submitvalue =Enviar/>
< / form>

这只会发生在:

<$ p $

< input type =fileid =videoname =videoclass =validate ['required','video']cols =100>

存在!

var_dump($ _POST) $ _ FILES print_r()等什么都不返回我试图创建一个类型文件,如 img_p_child [] 的输入上的数组,但没有。



如何解决这个问题?



感谢您抽出宝贵时间!




我忘了提及,现在我在这个第二个输入字段中发送一个图像文件并且工作,但是没有.FLV文件。所以我怀疑有一个最大的权限,我需要改变php.ini,如果是这样的话,我很抱歉! :X

解决方案

摘自 php.net
$ b


post_max_size会影响文件上传。要上传大文件,此
值必须大于upload_max_filesize。如果配置脚本启用了内存限制
,则memory_limit也会影响文件
的上传。一般来说,memory_limit应该大于
post_max_size。当使用整数时,该值以
字节度量。速记符号也可以使用。如果发布数据
的大小大于post_max_size,则$ _POST和$ _FILES超全局变量
是空的。这可以以各种方式进行跟踪,例如,通过将
$ _GET变量传递给处理数据的脚本,然后检查是否设置了
$ _GET ['processed']。



< memory_limit设置允许脚本
分配的最大内存量(以字节为单位)。这有助于防止为
编写的脚本写得不好而耗尽了服务器上的所有可用内存。请注意,如果没有
内存限制,请将此指令设置为-1。


就是说,您需要更改有些东西在你的php.ini允许更大的上传:

pre $ upload $ max_filesize = 10M;
post_max_size = 20M;
memory_limit = 18M;

将以下内容添加到您的根目录中的.htaccess文件中。

  php_value upload_max_filesize 10M 
php_value post_max_size 20M
php_value memory_limit 18M

显然,这些尺寸会根据您的需求而有所不同。 这里有一篇不错的文章关于增加你的上传大小。


I'm not finding a way to understand and fix this and I've done a lot.

I've got a script, wish is a simple form, that sends a file trough POST. The second file, process the info.

By default, I give to the user a few fields, one of them being a input field of type "file" and there's also, a few "hidden" one's, that gives me values to work with on POST.

I found that, when adding a new input of type "file", the $_POST returns array 0, even $_FILES returns nothing. I have no idea how to fix this, and it works just fine when keeping the default input box of type "file".

<form id="formulario" enctype="multipart/form-data" action="projectos_processar.php" method="POST">

    Modo inserir projecto item!<br/><br/>
    <label>Imagem de apresentacao: </label>

    <input id="img_p_child" type="file" name="img_p_child" cols="100" value="" class="validate['required','image']" /><br/>

    <br/>
    <br/>

    <input type="file" id="video" name="video" class="validate['required','video']" cols="100">

    <br/>                       
    <br/>
    <hr>
    Publicar o item ? <br/>
    <br/>
    <br/>                       

    Sim <input type="radio" name="published" value="1"><br>
    Nao <input type="radio" name="published" value="0" checked="true"><br>

    <hr>

    <!-- INICIO:: CAMPOS EM MODO HIDDEN -->
    <input type="hidden" value="center" name="crop_X_Y" />
    <input  type="hidden" value="assets/publicidade/FURIOUS01/" name="stringDirPagina" />
    <input  type="hidden" value="128" name="parent_id" />
    <input  type="hidden" value="projectos_item" name="pagina_id"/>
    <input  type="hidden" value="inserir" name="tarefa" />
    <!-- FIM:: CAMPOS EM MODO HIDDEN -->

    <br/>
    <input type="submit" value="Enviar" />
</form>

This only happens when:

<input type="file" id="video" name="video" class="validate['required','video']" cols="100">

Exists!

var_dump( $_POST ), or $_FILES, print_r(), etc return nothing. I've trieed to create an array on the input of type "files", like img_p_child[], but nothing.

How to solve this ?

Thanks for taking your time!


I forgot to mention that, I trieed right now sending a image file in this second input field and works, but not with .FLV file. So I suspect there's a maximum permission, that I need to change on php.ini, if this is the case, I'm sorry! :X

解决方案

Taken from php.net:

post_max_size affects file upload. To upload large files, this value must be larger than upload_max_filesize. If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size. When an integer is used, the value is measured in bytes. Shorthand notation may also be used. If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. , and then checking if $_GET['processed'] is set.

memory_limit sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

That being said, you need to change some things in your php.ini to allow larger uploads:

upload_max_filesize = 10M;
post_max_size = 20M;
memory_limit = 18M; 

Add the below to your .htaccess file in the you root directory.

php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 18M 

Obviously, these sizes will vary based on your needs. Here is a nice article on increasing your upload size.

这篇关于添加新的输入类型“文件”后,$ _POST变空。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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