每个上传文件附加多个文件的html输入类型文件

I have a form that contains an input of type file that when submitted is sent to a php file using ajax and form data.

my html code is:

<input type="file" name = "attachments" multiple>

and on the php side:

echo count($_FILES["attachments"]);
foreach($attachments as $attached)
   query("INSERT INTO attachments (`file_id`,`message_id`,`file`)VALUES (NULL , '$message_id','$attached')");

The problem is that when uploading one single file the echo statement is echoing 5 even though on the html side it shows , and when inserting into the database the file is inserted as 5 blob objects.

When I use name = "attachments" (not an array) I get the following inserted into the database:

file_id message_id file

284     19         [BLOB - 11 B]

285     19         [BLOB - 9 B]

286     19         [BLOB - 20 B]

287     19         [BLOB - 1 B]

288     19         [BLOB - 3 B]

When I use name = "attachments[]" I get the following inserted 5 times:

file_id message_id file

289     19         [BLOB - 5 B]

Does anyone know how this is happening ?