【问题标题】:$_FILES not working and gives no errors$_FILES 不工作并且没有给出错误
【发布时间】:2013-11-04 23:54:43
【问题描述】:

这是我的 html 页面,其中包含表单:

<html>
    <head>
        <meta charset="UTF-8"/>
    </head>
    <body style="text-align:center;" >
        <form id="upload" action="file_upload.php" method="post" enctype="multipart/form-data">
            <input type="hidden" name="MAX_FILE_SIZE" value="12412412" /> 
            <label for="file">Dosya Adı:</label>
            <input type="file" mame="file" id="file"/>
            <br/>
            <input type="submit" name="submit" value="Yükle"/>
        </form>
    </body>
</html>

这是我的 file_upload.php 文件:

<pre>
    <?php print_r($_FILES); ?>
</pre>

<?php
    if( $_FILES["file"]["error"] > 0 ){
        echo 'Error : ' . $_FILES["file"]["error"]. '<br/>';
    }
    else {
        echo "File : " . $_FILES["file"]["name"] . "<br/>";
        echo 'File Type : ' . $_FILES["file"]["type"] . '<br/>';
        echo 'File temp adr: : ' . $_FILES["file"]["tmp_name"] . '<br/>';
    }
?>

我的 php 信息记录:

file uploads : on
max file uploads : 20
upload max file size : 32M
post max size : 32M

我的 tmp 文件夹权限设置为 777。我正在使用 bitnami mamp stack 5.4.9 上的 mac os 10.9

file_upload.php 给了我这个:

Array
(
)

File :
File Type :
File temp adr: : 

我尝试在我的 html 表单中使用和不使用 &lt;input type="hidden" name="MAX_FILE_SIZE" value="12412412" /&gt;。我在互联网上搜索了每个站点,但找不到问题。

【问题讨论】:

  • 如果你使用 fiddler(或任何其他你更喜欢的 http/network 嗅探器)并查看真正的请求怎么办?
  • 你有错误的属性,检查我的答案:-)

标签: php linux apache forms http-post


【解决方案1】:

你有错误的属性:

<input type="file" mame="file" id="file"/>

应该是name:

<input type="file" name="file" id="file"/>

这就是为什么$_FILES 是空的;将属性mame 修复为name 后,它将起作用。

【讨论】:

  • 非常感谢。我的错误。对于试图解决此类问题的人来说,这是一个很好的记录。
猜你喜欢
  • 1970-01-01
  • 2021-04-08
  • 1970-01-01
  • 1970-01-01
  • 2014-09-30
  • 1970-01-01
  • 1970-01-01
  • 2017-02-02
  • 1970-01-01
相关资源
最近更新 更多