PHP 个文件未使用 $_FILES 数组检测到
PHP files not detected using the $_FILES array
问题
$_FILES['file'] 数组已设置,但每当我尝试使用它时它都是空的。
我试过的
- 谷歌搜索
- 在 php.ini(Xampp 和项目文件根目录)
中将文件上传设置为开
- 一次上传一个文件(只是尝试解决问题
- 调试整个代码一个月试图解决这个问题
我所知道的事实
- onSubmit 的路径是正确的
- 表单中输入的名字和$_FILES['file']后面的名字完全一致
- 表单具有所有必需的属性
- 输入有 type="file" 和 multiple
我的表单代码(HTML)和文件引擎代码(PHP)
<html>
<form method="POST" action="../php/post.php" enctype="multipart/form-data">
<h3>Title</h3>
<input type="hidden" name="case" value=1>
<input type="title" name="pname">
<h3>Message</h3>
<input type="message" name="pmsg">
<h3>Images</h3>
<input type="file" name="pimg[]" multiple>
<input class="submit" type="submit" value="Upload">
</form>
</html>
PHP
<?php
if (!empty($_FILES['file']['pimg'])){
$noFiles = 1;
echo "Files found...\n";
} else {
$noFiles = 0;
echo "Files not found...\n";
echo (!empty($_FILES['file']['pimg']));
echo $_FILES['file']['pimg'][0];
}
?>
输出
If判断数组为空,最后回显导致错误
你离得不远了。
$_FILES['file']['pimg'] 应该是 $_FILES['pimg']
您还应该检查是否选择了某些内容。 $_FILES['pimg']['size'] 检查文件大小。如果为 0,则不选择任何内容
这种方式可行。
<?php
if ($_FILES['pimg']['size'] != 0){
$noFiles = 1;
echo "Files found...\n";
echo $_FILES['pimg']['name'][0];
} else {
$noFiles = 0;
echo "Files not found...\n";
/* This will always be empty placed here as no files have been found */
//echo (!empty($_FILES['file']['pimg']));
//echo $_FILES['file']['pimg']['name'][0];
}
?>
问题
$_FILES['file'] 数组已设置,但每当我尝试使用它时它都是空的。
我试过的
- 谷歌搜索
- 在 php.ini(Xampp 和项目文件根目录) 中将文件上传设置为开
- 一次上传一个文件(只是尝试解决问题
- 调试整个代码一个月试图解决这个问题
我所知道的事实
- onSubmit 的路径是正确的
- 表单中输入的名字和$_FILES['file']后面的名字完全一致
- 表单具有所有必需的属性
- 输入有 type="file" 和 multiple
我的表单代码(HTML)和文件引擎代码(PHP)
<html>
<form method="POST" action="../php/post.php" enctype="multipart/form-data">
<h3>Title</h3>
<input type="hidden" name="case" value=1>
<input type="title" name="pname">
<h3>Message</h3>
<input type="message" name="pmsg">
<h3>Images</h3>
<input type="file" name="pimg[]" multiple>
<input class="submit" type="submit" value="Upload">
</form>
</html>
PHP
<?php
if (!empty($_FILES['file']['pimg'])){
$noFiles = 1;
echo "Files found...\n";
} else {
$noFiles = 0;
echo "Files not found...\n";
echo (!empty($_FILES['file']['pimg']));
echo $_FILES['file']['pimg'][0];
}
?>
输出
If判断数组为空,最后回显导致错误
你离得不远了。 $_FILES['file']['pimg'] 应该是 $_FILES['pimg'] 您还应该检查是否选择了某些内容。 $_FILES['pimg']['size'] 检查文件大小。如果为 0,则不选择任何内容
这种方式可行。
<?php
if ($_FILES['pimg']['size'] != 0){
$noFiles = 1;
echo "Files found...\n";
echo $_FILES['pimg']['name'][0];
} else {
$noFiles = 0;
echo "Files not found...\n";
/* This will always be empty placed here as no files have been found */
//echo (!empty($_FILES['file']['pimg']));
//echo $_FILES['file']['pimg']['name'][0];
}
?>