简体   繁体   English

PHP上传表格最多可以上传16个文件

[英]PHP upload form won't upload more than 16 files

The files are relatively small XMLs that are far below the max upload limit, and I've adjusted my max_file_upload value in php.ini to 30. All of the files can be uploaded in any combination up to 16 of them. 这些文件是相对较小的XML,远远低于最大上传限制,我已经将php.ini中的max_file_upload值调整为30。所有文件都可以任意组合上传,最多可以上传16个。 What's more, the form will not actually "POST." 而且,该表格实际上不会“过帐”。 It will action over to the next page, but I've put in some code to display text if the form has been submitted, which it won't if more than 16 files are selected. 它将移至下一页,但是如果提交了表单,我已经输入了一些代码来显示文本,如果选择了16个以上的文件,则不会显示文本。 I'm at a loss for this one, not much help around the web either. 我对此很茫然,在网络上也没有太多帮助。

<form method="post" enctype="multipart/form-data" name="uploadForm" id="uploadForm" action="?pa=uxf">
        <table border="0" cellspacing="5" cellpadding="5">
          <tbody>
            <tr>
                <td valign="top"><label for="fileField"><strong>Upload XML Files to Repository:</strong></label><br /><?php
            if(isset($_POST['upload'])) {
                $fileCount = count($_FILES['fileToUpload']['tmp_name']);

                echo '<br /><br />File Count: '.$fileCount.'<br />';

                for ($i = 0; $i < $fileCount; $i++) {
                    echo '<br />';
                    $target_dir = 'uploads/';
                    $target_file = $target_dir.basename($_FILES['fileToUpload']['name'][$i]);
                    $uploadOk = 1;
                    $fileType = pathinfo($target_file,PATHINFO_EXTENSION);
                    $check = filesize($_FILES['fileToUpload']['tmp_name'][$i]);
                    if($check !== false) {
                        echo '<span style="color: #00AA00">File is an xml.</span><br />'.$check['mime'];
                        $uploadOk = 1;
                    } else {
                        echo '<span style="color: #FF0000">File is not an xml.</span><br />';
                        $uploadOk = 0;
                    }
                    if (file_exists($target_file)) {
                        echo '<span style="color: #FF0000">Sorry, <strong>'.$target_file.'</strong> already exists.</span><br />';
                        $uploadOk = 0;
                    }
                    if ($_FILES['fileToUpload']['size'][$i] > 50000000) {
                        echo '<span style="color: #FF0000">Sorry, your file is too large. Must be less than 50MG.</span><br />';
                    $uploadOk = 0;
                    }
                    if($fileType != 'xml') {
                        echo '<span style="color: #FF0000">Sorry, only XML files are allowed.</span><br />';
                        $uploadOk = 0;
                    }
                    if ($uploadOk == 0) {
                    echo '<span style="color: #FF0000">Sorry, your file was not uploaded.</span><br />';
                    } else {
                        if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'][$i], $target_file)) {
                        echo '<span style="color: #00AA00">The file '.basename($_FILES['fileToUpload']['name'][$i]).' has been uploaded.</span><br />';
                        } else {
                        echo '<span style="color: #FF0000">Sorry, there was an error uploading your file.</span><br />';
                        }
                    }
                }
            } ?>
                    <table width="100%" border="0" cellspacing="5" cellpadding="5">
                        <tbody>
                            <tr valign="top">
                                <td><input type="file" name="fileToUpload[]" id="fileToUpload[]" multiple></td>
                                </tr>
                            <tr valign="top">
                                <td><input type="submit" name="upload" id="upload" value="Upload XML"></td>
                                </tr>
                            </tbody>
                        </table></td>
                <td valign="top"><strong>Uploaded Files List:</strong><br><?php
            $int = 1;
            foreach (new DirectoryIterator($directory) as $fileInfo) {
                if($fileInfo->isDot()) continue;
                $file =  $fileInfo->getFilename();
                echo $int.'. <a href="'.$directory.$file.'">'.$file.'</a><br />';
                $int++;
            } ?></td>
                </tr>
            </tbody>
        </table>
      </form>

In addition to max_file_upload , there are two other ini settings that concern file uploads that may be relevant. 除了max_file_upload以外 ,还有其他两个ini设置,它们与可能相关的文件上传有关。

upload_max_filesize (default 2 MB) limits the per-file upload size, and post_max_size (default 8 MB) limits the total size of POST content, including file uploads. upload_max_filesize (默认2 MB)限制每个文件的上载大小,而post_max_size (默认8 MB)限制POST内容(包括文件上载)的总大小。

If you are running afoul of either limit, that can result in the behavior you are seeing. 如果您违反上述任一限制,则可能会导致您看到的行为。

As both of these are relevant before php code beings executing, you'll need to look at your php.ini (and/or .htaccess settings, as the case may be) and ensure that they are set to a level that will allow for all of your POST content to be accepted. 由于这两项在执行PHP代码之前都是相关的,因此您需要查看php.ini (和/或.htaccess设置,视情况而定),并确保将其设置为允许您所有的POST内容都将被接受。

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

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