无法进行图像更新


image update cannot takeplace

我正试图通过使用php文件上传更新查询将图像上传到数据库,其中数据库已经包含一个文件。这是我的代码,问题是我没有得到新文件。

if (isset($_POST["events"]) && isset($_POST["description"])) 
{
    $id = $_POST["id"]; 
    $title = $_POST["events"];
    $_POST["description"] = trim($_POST["description"]);
    $description = $_POST["description"];
    if(isset($_POST['images']) && !empty($_POST['images']))
    {
        $filetmp = $_FILES["images"]["tmp_name"];
        $filename = $_FILES["images"]["name"];
        $filetype = $_FILES["images"]["type"];
        $filepath = "photo2/".$filename;
        move_uploaded_file($filetmp,$filepath);
    }
    else
    {
        $filepath = $_POST['old_image_path'];
    }
    $update1 = update_query($title,$description,$filepath,$id);
    if($update1)
    {
        header("location:hotel1_galery_event.php?msg=Update Sucess");
    }
}

HTML代码预览

<form action="hotel1_galery_eventedit.php" method="post" class="col-sm-4" enctype="multipart/form-data">
    <input type="hidden" name="id" value="<?php echo $val->event_id;?>">
    <div class="form-group has-info">
        <label class="control-label" for="inputSuccess">Event title</label>
        <input type="text" class="form-control" name="events" value="">
    </div>                                   
    <div class="form-group has-info">
        <label class="control-label" >Event Description</label>
        <textarea name="description" class="form-control text-left" rows="3">
        </textarea>
    </div>
    <div class="form-group has-info">
        <label>Event Related images</label>
        <input type="hidden" name="old_image_path"  value="<?php  echo $val->image_path?>">
        <input type="file" name="images" value="something">
    </div>
    <button type="submit" class="btn btn-primary">
        <span>UPDATE</span>
    </button> 
</form>

input type='file'在$_FILES 中POST您的文件

所以不是这个

 if(isset($_POST['images']) && !empty($_POST['images']))

你必须检查你的状况

if (!empty($_FILES['images']['name'])) {
    $filetmp = $_FILES["images"]["tmp_name"];
    $filename = $_FILES["images"]["name"];
    $filetype = $_FILES["images"]["type"];
    $filepath = "photo2/" . $filename;
    move_uploaded_file($filetmp, $filepath);
}