我在codeigniter中有编辑表单,我有15个以上的图像文件,而我在数据库中更新它更新的图像,但即使不是以它的形式更新图像并保存为空或空路径。但我需要没有更新所有15个文件的解决方案应该回溯它存储在数据库中的相同的旧图像路径。请你们为此提供更好的解决方案。
我的编辑表单
控制器:
if($this->input->post('submit'))
{
if($_FILES['file']['name']!='')
{
$filename = $_FILES['file']['name'];
$file_name1 = "upload_".$this->get_random_name()."_".$filename;
$_SESSION['file_upload']=$file_name1;
$file ="uploads/images/".$file_name1;
}
if($_FILES['file1']['name']!='')
{
$filename = $_FILES['file1']['name'];
$file_name2 = "upload_".$this->get_random_name()."_".$filename;
$_SESSION['file_upload']=$file_name2;
$file ="uploads/images/".$file_name2;
}
$query = $this->scener_model->popular_upload($file_name1,$file_name2)
}
答案 0 :(得分:0)
如果你是空的,那么传递隐藏的输入值,否则就像这样传递新上传的值..
if(!empty($_FILES()){
//your uploaded value here
} else {
//hidden attribute value
}
答案 1 :(得分:0)
如果($这 - >输入 - >柱( 'submit1')){
$titlemain = $this->input->post('title_main');
$price = $this->input->post('price');
$package = $this->input->post('package');
$titleinner = $this->input->post('title_inner');
$city_package = $this->input->post('city_packge');
if(!empty($count =count($_FILES['file1']['name']))){;
for($i=0; $i<$count;$i++){
$filename1=$_FILES['file1']['name'][$i];
//print_r($filename);exit;
$filetmp=$_FILES['file1']['tmp_name'][$i];
$filetype=$_FILES['file1']['type'][$i];
$images = $_FILES['file1']['name'];
$filepath="uploads/images/".$filename1;
move_uploaded_file($filetmp,$filepath);
}
$filename1 = implode(',',$images);
}
else{
$filename1=$this->input->get('iti_image2') ;
//print_r( $data['newz1']);exit;
}
我的观看页面:
<div class="col-sm-8">
<input type="button" id="get_file" value="Grab file">
<?php
$imss= $result->iti_image2;
?>
<input type="file" id="my_file" name="file3[]" value="<?php echo $imss ?>" multiple/>
<div id="customfileupload">Select a file</div>
<input type="hidden" class="btn btn info" id="image" name="iti_image2" accept="image" value="<?php echo $result->iti_image2; ?>" multiple/ >
</div>
<script>
document.getElementById('get_file').onclick = function() {
document.getElementById('my_file').click();
};
$('input[type=file]').change(function (e) {
$('#customfileupload').html($(this).val());
});
</script>
</div>
我的模特:
function itinerary_updte($filename4,$filename5){
$update_itinerarys = array(
'iti_image2' =>$filename4,
'iti_image3' =>$filename5
);
$this->db->where('id', $id);
$ result = $ this-&gt; db-&gt; update('sg_itinerary',$ update_itinerarys);
返回$ result;
}
答案 2 :(得分:0)
最后我们找到了一个图像更新解决方案,有些教程可以看到链接 &#34; http://www.2my4edge.com/2016/04/multiple-image-upload-with-view-edit.html&#34;
感谢那些给我的帖子提供逻辑和评论的伙伴们,非常感谢@ankit singh @Lll