【发布时间】:2014-01-03 10:50:26
【问题描述】:
我有以下html代码最多可以上传8张图片:
<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代码
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'] . "");
}
问题是当我只上传 img2 并保存表单时,其他现有图像已从数据库中删除。当我上传 img1 和 img2 时,一切都很好。如何编辑 php 代码,以便仅上传 img3 并保留 img 1 和 img2 ?
【问题讨论】:
-
您尝试了什么,什么没有奏效?您甚至了解您发布的代码吗?
-
etc for 2,3,4....放下那把霰弹枪!
标签: php html image upload jquery-ui-sortable