PHP $_FILES 多文件上传问题 [英] PHP $_FILES multiple file uploading problem

查看:52
本文介绍了PHP $_FILES 多文件上传问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用 PHP 上传多个文件时遇到了一个小问题,

I have a little problem with uploading multiple files in PHP ,

我有这个 html 表单:

i have this html form:

<form method="post" action="upload.php" enctype="multipart/form-data">
    <input type="file" name="myfile[]"  />
    <input type="submit" />
</form>

这是upload.php :

and this is the upload.php :

<?php print_r( $_FILES ); ?> 

当我发送文件时,它会显示:

when i'm sending a file it show me this:

 Array
(
[myfile] => Array
    (
        [name] => Array
            (
                [0] => Krw_Qe4QKmI.mp3
            )

        [type] => Array
            (
                [0] => 
            )

        [tmp_name] => Array
            (
                [0] => 
            )

        [error] => Array
            (
                [0] => 1
            )

        [size] => Array
            (
                [0] => 0
            )

    )

 )

到目前为止一切都很好.

so far so good.

当我将表单升级到这个时,问题就开始了:

the problem starts when i upgrade my form to this one :

<form method="post" action="upload.php" enctype="multipart/form-data">
    <input type="file" name="myfile[]"  />
    <input type="file" name="myfile[]"  />
    <input type="submit" />
</form>

现在,当我发送 2 个文件时,它显示给我:

now , when i send 2 files , it show me this :

Array
(
)

那么,这里有什么问题?谢谢你,莫尔.

so , what's the problem here? thank you , Mor.

推荐答案

这里有很多建议.我试一试.这是基于@Pekka 的评论.

A lot of suggestions here. I'll give it a go. This is based on @Pekka 's comment.

我看到您正在使用 mp3 进行测试,这可能超出了 PHP 上传限制.这是因为在您的第一个示例中,您实际上有一个上传错误代码 1:上传的文件超出了 php.ini 中的 upload_max_filesize 指令..所以即使你的拳头上传也不起作用.成功上传的错误代码始终为 0.

I see you're testing with mp3s, which probably exceed PHP upload limit. This is because in your first example, you actually have an upload error code 1: The uploaded file exceeds the upload_max_filesize directive in php.ini.. So even your fist upload didn't work. A successful upload always has 0 as the error code.

upload_max_filesize = 10M(或20M,或300M;小心那个M)修改你的php.ini> - 这意味着 兆字节 - 省略,带来很多头痛.

Modify you php.ini with upload_max_filesize = 10M (or 20M, or 300M; careful about that M - which means megabytes - as omitted, brings alot of headache.

我建议使用较小的文件进行测试,因为我看到您的上传限制为 2M.

I suggest testing with smaller files, as I see you have a limit of 2M for uploading.

进一步阅读.

这篇关于PHP $_FILES 多文件上传问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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