In my application I want to store vehicle details to mysql database. There is image field which is having more than 1 images.(select from the user) It may be 3 ,4 ,5 etc.image table has image id and image path field.When submit button click I want to add images to vehicle folder(this part working) and all images paths to the database. Really I'm wired now. I don't know how to add multiple images record to the database. Please help me. This is my existing code.
Code:
if (isset($_POST['Submit'])) { $vehicles_pk = mysql_insert_id(); // get last inserted vehicle id $number_of_file_fields = 0; $number_of_uploaded_files = 0; $number_of_moved_files = 0; $uploaded_files = array(); $upload_directory = dirname(__file__) . '/vehicles/'; //set upload directory // * we get a $_FILES['images'] array , // * we procee this array while iterating with simple for loop // * you can check this array by print_r($_FILES['images']); for ($i = 0; $i < count($_FILES['images']['name']); $i++) { $number_of_file_fields++; if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not $number_of_uploaded_files++; $uploaded_files[] = $_FILES['images']['name'][$i]; if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) { $number_of_moved_files++; } } } $name= implode(',', $uploaded_files); echo $name; // this will print 1.jpg,2.jpg
Comment