I need to amend an image upload form so I can upload more than one image (6 to be exact). I've tried adding another input and changing the name value as suggested by others, but it still shows up with the same image duplicated from the first input. I know it's probably something simple, but I'm not a PHP developer so I haven't been able to find a solution.
Here's the code for uploading images:
if(isset($_FILES['image']) && $_FILES['image']['tmp_name'] != '') {
$tempext = explode('.', $_FILES['image']['name']);
$tempext = strtolower($tempext[count($tempext) - 1]);
switch($tempext) {
case 'jpg':
case 'jpeg':
$ext = '.jpg';
break;
default:
$ext = false;
}
if($ext != false && move_uploaded_file($_FILES['image']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/img/profiles/' . $id . $ext)) {
$imagesuccess = chmod($_SERVER['DOCUMENT_ROOT'] . '/img/profiles/' . $id . $ext, 0644) ? 'yes' : 'no';
} else {
$imagesuccess = 'no';
}
}
And for the input:
<div class="control-container<?php if((isset($_FILES['image']) && !empty($_FILES['image']['name']))) echo ' error'; ?>">
<label for="image">Large Image</label>
<div class="multifield">
<?php
if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/img/profiles/' . $id . '.jpg')) {
echo '<img src="/img/profiles/' . $id . '.jpg?' . rand() . '" width="310px" />';
}
?>
<input type="file" name="image" id="image" />
</div>
</div>
Any help would be much appreciated.
Thanks