I have a HTML form which I send to a php page, the form seems to upload some files but not others. For example if I upload six files, what seems to happen is 2 or 3 will upload and the others won't. I also send the filename to a database, which shows the same 2 or 3 files repeated.
I have checked all the timeout options, post sizes and cannot fathom the cause. I haven't placed any restrictions on the file types (yet).
The HTML code:
<form action="" method="POST" enctype="multipart/form-data">
<label for="frm-activity-files"><h3>Attach files:</h3></label>
<input type="file" multiple="multiple" name="frm-activity-files[]">
<p>Files limited to 10MB each.</p>
</form>
The PHP Code:
<?php
$frm_upload_count = 0;
$frm_upload_path = $_SERVER['DOCUMENT_ROOT'].'/uploads/';
if (!empty($_FILES['frm-activity-files']['tmp_name'])) {
$error = '';
$frm_upload_count = count($_FILES['frm-activity-files']['tmp_name']);
for ($i = 0; $i < $frm_upload_count; $i++) {
$frm_upload_newname = (md5(date('Y-m-d H:i:s:u')).'-'.date('YmdHis'));
$frm_upload_file = $_FILES['frm-activity-files']['name'][$i];
$frm_upload_temp = $_FILES['frm-activity-files']['tmp_name'][$i];
$frm_upload_ext = pathinfo($frm_upload_file, PATHINFO_EXTENSION);
$frm_upload_rename = $frm_upload_newname.'.'.$frm_upload_ext;
move_uploaded_file($frm_upload_temp, $frm_upload_path.$frm_upload_rename);
$sql_insert_attachment = 'INSERT INTO data__attachments(attachment_auuid, attachment_uid, attachment_filename) VALUES (?,?,?)';
$stmt_insert_attachment = $mysqli->prepare($sql_insert_attachment);
$stmt_insert_attachment->bind_param("sss", $frm_uuid, $frm_uid, $frm_upload_rename);
$stmt_insert_attachment->execute();
$frm_upload_newname = "";
$frm_upload_file = "";
$frm_upload_temp = "";
$frm_upload_ext = "";
$frm_upload_rename = "";
$error .= $_FILES['frm-activity-files']['error'][$i]; // get the error
}
}