【发布时间】:2016-01-09 07:40:48
【问题描述】:
这些文件是相对较小的 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>
【问题讨论】:
-
error_reporting(E_ALL); ini_set('display_errors', 1);如果您还没有添加这两行,您可以添加吗?也许您的控制参数之一有错误。
-
我在文档中将这两行添加到更高的位置,但我已经解决了我的问题。但是非常感谢您为解决方案做出贡献,aaronxxx :)。
标签: php html file-upload