使用codeigniter上传多个图像时出错

时间:2016-02-26 08:53:23

标签: php mysql codeigniter

上传多个图片时,我发现一个错误,表格的值在显示时变为空 这是我的控制器..

public function add_images()

 {
  $data['active_mn']='add_images';
  $this->form_validation->set_rules('title','title','required');
  $this->form_validation->set_rules('parentname','parent category','required');
  $this->form_validation->set_rules('subname','sub category','required');
  $this->form_validation->set_rules('code','code','required');
  $this->form_validation->set_rules('description','Description','required');
  $this->form_validation->set_rules('size','Size','required');  

  if($this->form_validation->run()==TRUE)
    {
      $image=array_values($this->session->userdata('image'));
      $images=json_encode($image);

       $data = array('title'=>$this->input->post('title'),
                     'code'=>$this->input->post('code'),
                     'select_image'=>$this->input->post('select_image'),
                     'select_wear'=>$this->input->post('select_wear'),
                     'image'=>$images,
                     'category_id'=>$this->input->post('subname'),
                     'size'=>$this->input->post('size'),
                     'description'=>$this->input->post('description'));
      $product=$this->roxmodel->add_gallery($data);
      if($product)
      {
        $data=array();
        $colors=array_filter($this->session->userdata('colors'));
        /*creating a multidiemensional array to batch insert*/
        foreach ($colors as $color) 
        {
          $new_array=array('product_id'=>$product,'color'=>$color);
          array_push($data, $new_array);
        }

        $product=$this->roxmodel->add_product_color($data);
        $this->session->unset_userdata('image');
        $this->session->unset_userdata('colors');
        $this->session->set_flashdata('message', 'Product added Successfully.');
        redirect('admin_control/view_images');


      }
      else
        {
          //$this->session->unset_userdata('image');
          $this->session->set_flashdata('message', 'Insertion Failed.');
          redirect('admin_control/add_images');
        }

    }
//$this->session->unset_userdata('image');

//var_dump($data['sub_category']);
$data['parent']=$this->roxmodel->get_parentcategory();
$this->load->view('add_images',$data);
  }

我的观看页面就是这个......

  <?php foreach ($detail as $row) { ?>
<div class="col-md-3 col-sm-1">
<?php $images = json_decode($row->image);
 //print_r($images); ?>
      <div  class="image-box"> 
       <!-- <textarea id="F<?php echo $row->id;?>" hidden> <?php echo $row->image;?></textarea>

              <img  width="100" src="<?php echo base_url()?>images/<?php echo $images[0] ?>" alt="" file="F<?php echo $row->id;?>" class="img-responsive view-more">
              -->

<?php 
  if($images){
   foreach($images as $image):?>
         <img width="100" height="100" src="<?php echo    base_url();?>images/<?php echo $image;?>" class="img-responsive"  alt="">
          <?php endforeach;
      }
        else
          {
            ?>
      <img width="100" height="100" src="<?php echo base_url();?>images/<?php echo $row->image;?>" class="img-responsive"  alt="">
        <?php
        };
        ?>  
        <div class="edit-box">
          <h4><?php echo $row->title; ?> 

          </h4>
          <span class="rg-br" type="button">
           <a href="<?php echo base_url();?>admin_control/edit_gallery/<?php echo $row->id;?>"><i class="fa fa-pencil-square-o" data-toggle="tooltip" data-placement="bottom" title="Edit"></i></a> 

         </span>
            <span>
            <a class="portfolio" data-toggle="modal" onclick='return deleteItem()'  name="delete" id="title" img="img1446224811.jpg" big-img=""  title="Delete" href="<?php echo base_url();?>admin_control/delete_image/<?php echo $row->id;?>/<?php echo $row->image;?>"><i class="fa fa-trash-o"  data-toggle="tooltip" data-placement="bottom" title="Delete"></i></a></span>
          <h5><!--  <?php echo $row->description; ?> --></h5>
        </div>
      </div>
    </div>

     <?php } ?>

此处图像未显示且表格中的图像值为空

0 个答案:

没有答案