gpt4 book ai didi

PHP 上传表单不会上传超过 16 个文件

转载 作者:行者123 更新时间:2023-11-28 03:01:00 24 4
gpt4 key购买 nike

文件是相对较小的 XML,远远低于最大上传限制,我已将 php.ini 中的 max_file_upload 值调整为 30。所有文件都可以以任意组合上传,最多 16 个。更重要的是,表单实际上不会“POST”。它将转到下一页,但如果表单已提交,我会添加一些代码来显示文本,如果选择的文件超过 16 个,则不会显示文本。我对此不知所措,在网络上也没有太多帮助。

<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>

最佳答案

除了max_file_upload ,还有另外两个 ini 设置涉及可能相关的文件上传。

upload_max_filesize (默认 2 MB)限制每个文件的上传大小,并且 post_max_size (默认 8 MB)限制 POST 内容的总大小,包括文件上传。

如果您违反任一限制,可能会导致您所看到的行为。

因为在执行 php 代码之前这两者都是相关的,所以您需要查看您的 php.ini(和/或 .htaccess 设置,因为情况可能是)并确保将它们设置为允许接受所有 POST 内容的级别。

关于PHP 上传表单不会上传超过 16 个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34687737/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com