For my internship, I need to built a webapp using PHP, the goal of the application is to make notes using voice recognition technology (javascript).
One part of the "make-a-note" section is the ability to upload multiple images/files. The notes and images that are related are stored in 2 different tables, and are linked based on the NoteID.
$countfiles = count($_FILES['images']['tmp_name']);
$note_query = "INSERT INTO Notes(NOTS_ID, NOTS_V_USRS, NOTS_V_ORGS, NOTS_A_TITLE, NOTS_A_TEXT, NOTS_C_TAGS, NOTS_V_CTRY, NOTS_T_FROM, NOTS_T_UNTIL) VALUES ('0', '" . $usr_id['USRS_ID'] . "','" . $organisation . "', '" . $note_title . "', '" . $note_text . "', '0', '" . $country . "', '" . $fromdate . "', '" . $untildate . "');";
$conn->query($note_query) or die($conn->error());
$lastid = $conn->insert_id;
$imagedata = array();
// FILE UPLOAD
if (isset($_FILES['images'])){
for($i=0; $i < $countfiles; $i++){
$file_name = $_FILES['images']['name'][$i];
$file_tmp = $_FILES['images']['tmp_name'][$i];
array_push($imagedata, $file_name);
$desired_dir="./uploads/imgs/";
move_uploaded_file($file_tmp, $desired_dir.$file_name);
$img_query = "INSERT INTO Images(IMGS_ID, IMGS_V_USRS, IMGS_T_NAME, IMGS_V_NOTS) VALUES ('0', '" . $usr_id['USRS_ID'] . "', '" . $desired_dir.$file_name . "', '" . $lastid . "');";
$conn->query($img_query);
}
}
The part in the form where the file gets selected:
<input type="file" name="images[] multiple">
When I fill in the form, and upload for example 2 images, it just skips over the code, meaning, no files get uploaded/inserted in the database. The "Note" part is added correctly.
Any suggestion on how come this does not work? Or what do I need to change?
Thanks alot!
Regards, Dries :)
EDIT enctype=multipart/form-data
is also added