Since the question is general the answer will have to be general too:
- You need webform with POST action
- Upload files to the server
For 1-2 see answer with top votes at How to upload multiple files using PHP, jQuery and AJAX it looks promising (see this link updated PHP code below #3 section)
Save record to DB with images names or link images and DB record some other way What I'd do is 2 tables:
CREATE TABLE entry (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(64) NOT NULL
PRIMARY KEY (id)
);
CREATE TABLE entry_image(
id int(11) NOT NULL AUTO_INCREMENT,
image_path varchar(255) NOT NULL,
PRIMARY KEY (id)
);
3.1 Save 'entry'
3.2 Get it's id
3.3 INSERT all images filenames you have to 'entry_image'
Here's updated code:
mysql_query("INSERT INTO entry (name) VALUE('$name')");
$entryId = mysql_insert_id();
for($i=0; $i<count($_FILES['file']['name']); $i++){
$target_path = "uploads/";
$ext = explode('.', basename( $_FILES['file']['name'][$i]));
$target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext)-1];
if(move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {
echo "The file has been uploaded successfully <br />";
mysql_query("INSERT INTO entry_image (entry_id, image_path) VALUES ($entryId, '$target_path');
} else{
echo "There was an error uploading the file, please try again! <br />";
}
}
Note:
For sure you need to establish mysql connection and close it once done.
Also I'd do all mysql with prepared statements
Data validation (images), error checks, etc