2012-07-19 82 views
-4
<form action="entergallery.php" method="post" enctype="multipart/form-data"> 
<select id="photolib" name="photolib"> 
<?php 
$query = "SELECT * FROM `galleries`"; 
$res = mysqli_query($db, $query); 
while($rows = mysqli_fetch_row($res)){ 
    echo '<option value="'.$rows[3].'">'.$rows[1].'</option>'; 
} 
?> 
</select> 
<input type="file" name="uploads[]" multiple/> 
<input type="submit" id="upload" name="upload" value="Upload"/> 
</form> 

由于某种原因,此表单总是传递5的长度。输入gallery.php只是计数{$ _ FILES ['uploads']);即使没有输入任何文件,也总是输出5。我不知道如何解决这个问题。我已经在多个浏览器测试,这一点,在所有 由于同样的问题提前输入总是发送5个大小

回答

0

Instea这

count{$_FILES['uploads'])

使用

count($_FILES['uploads']['name'])

的d你会得到实际计数。

1

见$ _FILES数组结构

总是有5个元素。

$_FILES["file"]["name"] - the name of the uploaded file 
$_FILES["file"]["type"] - the type of the uploaded file 
$_FILES["file"]["size"] - the size in bytes of the uploaded file 
$_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server 
$_FILES["file"]["error"] - the error code resulting from the file upload 

如果你想检查$ _FILES为空,则需要检查上传错误,这样

<?php 
if ($_FILES["file"]["error"] > 0) 
    { 
    echo "Error: " . $_FILES["file"]["error"] . "<br />"; 
    } 
?> 

在你的情况下,有多个文件上传你具有结构:

array 
    'filesToUpload' => 
    array 
     'name' => 
     array 
      0 => string '2012-07-19_192449.jpg' (length=21) 
      1 => string '2012-07-19_192449.png' (length=21) 
     'type' => 
     array 
      0 => string 'image/jpeg' (length=10) 
      1 => string 'image/png' (length=9) 
     'tmp_name' => 
     array 
      0 => string '/tmp/phpBp3Pf7' (length=14) 
      1 => string '/tmp/php4A25Ly' (length=14) 
     'error' => 
     array 
      0 => int 0 
      1 => int 0 
     'size' => 
     array 
      0 => int 5263 
      1 => int 8681 

等,文件数可以在tmp_name数组中计算上传数组,例如