I've been reading up on form arrays on php.net and have had a stab at making a 5 picture upload form using the html arrays feature. Unfortunately I'm not near a computer to test it, so does this look like it should work,
The pictures should get put in /uploads/images/yyyy/mm/dd relative to the doc root, and the title, folder and filename should be stored into an sql table.
<?php
$year = date("Y");
$month = date("m");
$day = date("d");
$store_folder = $_SERVER['document_root'].'/uplods/images/'.$year.'/'.$month.'/'.$day;
if (isset($_POST['submitted'])) {
if ($_POST['terms'] == 'agree' && $_POST['privacy'] == 'agree') {
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
$final_location = $store_folder.'/'.$name;
* * if(move_uploaded_file($tmp_name, $final_location )){
$title = $title[$key];
$query = "INSERT INTO pictures (uid, title, folder, filename) VALUES ($id, $title, $store_folder, $name)"
//insert into table
}
}
}
}else{
echo '<p>You need to agree to the Terms and Conditions and Privacy Agreement.</p>';
}
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<fieldset>
<legend><img src="/images/icons/picture_add.png" alt="Upload Pictures" width="16" height="16" align="left" />Upload Pictures</legend>
<input type="file" name="pictures[]" /><input type="text" name="titles[]" size="15" maxlength="40"/>
<br/>
<input type="file" name="pictures[]" /><input type="text" name="titles[]" size="15" maxlength="40"/>
<br/>
<input type="file" name="pictures[]" /><input type="text" name="titles[]" size="15" maxlength="40"/>
<br/>
<input type="file" name="pictures[]" /><input type="text" name="titles[]" size="15" maxlength="40"/>
<br/>
<input type="file" name="pictures[]" /><input type="text" name="titles[]" size="15" maxlength="40"/>
<br/>
<label for="terms">Agree To <a href="legal/terms.php" target="_blank">T&C</a></label>
<input name="terms" type="checkbox" value="agree" checked/>
<br/>
<label for="age">Read Privacy?*</label>
<input name="age" type="checkbox" value="yes" checked/>
<br/><br/>
<div align="center">
<input type="submit" name="submit" value="Submit" />
<input name="reset" type="reset" value="Clear" />
</div>
</fieldset>
</form>
Thanks for the help