Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html php文件上载排序/顺序_Php_Html_Image_Upload_Jquery Ui Sortable - Fatal编程技术网

html php文件上载排序/顺序

html php文件上载排序/顺序,php,html,image,upload,jquery-ui-sortable,Php,Html,Image,Upload,Jquery Ui Sortable,我有以下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-

我有以下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      

img 1
img 2
...... 与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'] . "");
  }
if(数组\键\存在('img1',$\文件)){
如果(在_数组('image/jpg',$_文件['img1'])和&$_文件['img1']['error']=='0'中){
$img1=”http://www.*.com/tmp/“$findid。”_1.jpg”;
$name1=$findid.“_1.jpg”;
移动上传的文件($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
}
} 
...... 与img2、3、4、5、6、8相同
$images=内爆(“;”,数组过滤器(数组($img1、$img2、$img3、$img4、$img5、$img6、$img7、$img8));
如果(isset($\u GET['type'])&&&$\u GET['update']=='true'){
如果($images!=null){
mysql_query(“更新广告集标题='$title',图像='$images',描述='$description',priceValue='$priceValue'其中id=''''.''''.''))或die(mysql_error());
更新图像($un,$pw,$\u GET['id'],$images);
}否则{
mysql_查询(“更新广告集标题='$title',描述='$description',priceValue='$priceValue'其中id=''''.''''.'''))或死亡(mysql_error());
}
标题(“Location:edit.php?type=edit&id=“.$\u GET['id']”);
}

问题是当我只上传img2并保存表单时,其他现有图像将从数据库中删除。当我上传img1和img2时,一切都很好。如何编辑php代码,以便仅上传img3,并保留IMG1和img2?

您可以尝试更改行

if (array_key_exists('img1', $_FILES)) {


对所有的输入都这样做,img2,img3。。。等。

在上载图像之前,您需要验证并检查正在上载的图像:

试试下面的例子,而不是
array\u key\u存在('img1',$\u文件)

例如:


你有8个用于上传图像的输入,所以让它成为数组。这对你来说更简单、更有用。当你上传图像时,你需要编写8次代码来上传图像,这并不好,所以如果你愿意,可以像下面这样更改它

首先为所有输入创建数组

<input type="file" name="img[]" />

首先获取图像的数据,然后按如下方式更新详细信息

    $sql = "Select images from ads where id = '" . $_GET['id'] . "'";
    $q   = mysql_query($sql);
    if(mysql_num_rows($q) > 0){
        $res     = mysql_fetch_array($q);
        $imagesd = $res['images'];
        if(!empty($imagesd))
            $images  = $imagesd.';'.$images;
    }

    mysql_query("UPDATE ads SET title ='$title', images ='$images', description ='$description', priceValue ='$priceValue' WHERE id = '" . $_GET['id'] . "'") OR die(mysql_error());

你尝试了什么,什么不起作用?你明白你贴的代码了吗?
等等,2,3,4…
把枪放下<代码>$info=mysql\u查询(“从id=''.$findid'.''的信息中选择*”$info\u details=mysql\u fetch\u数组($ad)$images_ex=explode(“;”,$info_details['images']);if(empty($img1)){$img1=$images_-ex[0];}if(empty($img2)){$img2=$images_-ex[1];}这就成功了:)
<input type="file" name="img[]" />
foreach($_FILES[ 'img' ][ 'name' ] as $key=>$img)
{
    if($img!="")
    {
         move_uploaded_file($_FILES['img']['tmp_name'][$key], 'tmp/'.$img);

         //and here update code
    }
}
    $sql = "Select images from ads where id = '" . $_GET['id'] . "'";
    $q   = mysql_query($sql);
    if(mysql_num_rows($q) > 0){
        $res     = mysql_fetch_array($q);
        $imagesd = $res['images'];
        if(!empty($imagesd))
            $images  = $imagesd.';'.$images;
    }

    mysql_query("UPDATE ads SET title ='$title', images ='$images', description ='$description', priceValue ='$priceValue' WHERE id = '" . $_GET['id'] . "'") OR die(mysql_error());