I have the following html code to upload a maximum of 8 images:
<div class="form-group">
<label class="col-sm-3 control-label">img 1</label>
<div class="col-sm-6">
<input type="file" name="img1" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">img 2</label>
<div class="col-sm-6">
<input type="file" name="img2" />
</div>
</div>
...... same for img3,4,5,6,8
php code
if (array_key_exists('img1', $_FILES)) {
if (in_array('image/jpg', $_FILES['img1']) && $_FILES['img1']['error'] == '0') {
$img1 = "http://www.*.com/tmp/".$findid."_1.jpg";
$name1 = $findid."_1.jpg";
move_uploaded_file($_FILES['img1']['tmp_name'], 'tmp/'.$name1);
}
}
...... same for img2,3,4,5,6,8
<?php
$images = explode(';', $ad['images']);
if ($images != NULL) {
foreach ($images as $i => $filename) {
echo '<a href="'.$filename.'" target="_blank" ><img src="'.$filename.'" width="60px" height="55px" style="float:left; border:1px solid #B1C4DF;" /></a>';
}
}
?>
$images = implode(";",array_filter(array($img1,$img2,$img3,$img4,$img5,$img6,$img7,$img8)));
if (isset($_GET['type']) && $_GET['update'] == 'true') {
if($images != null){
mysql_query("UPDATE ads SET title ='$title', images ='$images', description ='$description', priceValue ='$priceValue' WHERE id = '" . $_GET['id'] . "'") OR die(mysql_error());
updateImages($un,$pw,$_GET['id'],$images);
}else{
mysql_query("UPDATE ads SET title ='$title', description ='$description', priceValue ='$priceValue' WHERE id = '" . $_GET['id'] . "'") OR die(mysql_error());
}
header("Location: edit.php?type=edit&id=" . $_GET['id'] . "");
}
the problem is when I only upload img2 and save the form other existing images are removed from the database. When I upload img1 and img2 everything is fine. How can I edit the php code so it is possible to only upload img3 for example and retain img 1 and img2 ?
etc for 2,3,4....
put that shotgun down! – Flosculus