-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 の長さを渡します。ファイルを入力しなくても、常に 5 が出力されます。これを解決する方法がわかりません。これを複数のブラウザでテストしましたが、すべて同じ問題があります よろしくお願いします

4

2 に答える 2

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

したがって、たとえば、filesUpload 配列の tmp_name 配列で計算できるファイル数

于 2012-07-19T14:00:30.947 に答える
0

これの代わりに

count{$_FILES['uploads'])

使用する

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

実際のカウントが得られます。

于 2012-07-19T15:06:29.417 に答える