我创建了add file upload function
和multiple file upload function
。
Add function
工作正常,但Edit function
无效。
提交EDIT
表单后, OLD VALUES 不会保存在数据库中。
该文件保存在其他文件夹中。
请帮助。
这是我的代码:controller file:
if(isset($_POST['additionalimage_exists']) && $_POST['additionalimage_exists'] != ''){
$temp_image = $_POST['additionalimage_exists'];
//echo $temp_image;die;
if(isset($_FILES['additional_images']['name']) && $_FILES['additional_images']['name'] != ""){
$errors= array();
$additional_eventimages = $_FILES['additional_images']['name'];
foreach($_FILES['additional_images']['name'] as $key => $tmpName) {
$additionalimages = $_FILES['additional_images']['name'][$key];
$file_type = $_FILES['additional_images']['type'][$key];
$file_size = $_FILES['additional_images']['size'][$key];
$file_tmp = $_FILES['additional_images']['tmp_name'][$key];
move_uploaded_file($file_tmp,"images/events/".$additionalimages);
}
}
else
{
$additional_eventimages = $temp_image;
}
}
查看文件:
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="additional-image">Additional Images</label>
<input type="file" class="form-control" name="additional_images[]" value="<?php echo $additional_images;?>" multiple="multiple">
<input type="hidden" name="additionalimage_exists" value="<?php echo $additional_images;?>" class="form-control-file" id="exampleInputFile" placeholder="Enter Image Text" aria-describedby="fileHelp">
<div>
<?php echo $additional_images;?>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
尝试使用此代码。
if(isset($_FILES['additional_images']['name']) && $_FILES['additional_images']['name'] != ""){
$errors= array();
$additional_eventimages = $_FILES['additional_images']['name'];
foreach($_FILES['additional_images']['name'] as $key => $tmpName) {
$additionalimages = $_FILES['additional_images']['name'][$key];
$file_type = $_FILES['additional_images']['type'][$key];
$file_size = $_FILES['additional_images']['size'][$key];
$file_tmp = $_FILES['additional_images']['tmp_name'][$key];
move_uploaded_file($file_tmp,"images/events/".$additionalimages);
} else if(isset($_POST['additionalimage_exists']) && $_POST['additionalimage_exists'] != ''){
$additional_eventimages = $_POST['additionalimage_exists'];
} else {
$additional_eventimages = "";
}