php - Codeigniter doesn't upload video files -


i have problem function upload video , images. can upload images not video don' know why. in , more code controller , form.

code in user_models php:

function newp($title,$post,$image,$video,$cat){ $id=$this->session->userdata('userid');  if($video!="")  {     $data=array(     'userid'=>$id,     'title'=>$title,     'forumpost'=>$post,     'categoryid'=>$cat,     'videourl'=>$video     ); } 

image:

else if($image!=""){     $data=array(     'userid'=>$id,     'title'=>$title,     'forumpost'=>$post,     'categoryid'=>$cat,     'imageurl'=>$image     ); }else{     $data=array(     'userid'=>$id,     'title'=>$title,     'forumpost'=>$post,     'categoryid'=>$cat,       );}    $this->db->insert('forum',$data);   }   } 

form:

<form method="post" enctype="multipart/form-data" action="<?php echo base_url();?>index.php/forum/newpk"> <div style="float:left;width: 95%;margin-top:5px;margin-left: 15px"> <h3> add post</h3> <div class="list-group" > <input type="text" required name="title" id="title" class="form-control" placeholder="title of post"> </div>  <div class="list-group"> <textarea name="post" class="form-control" style="min-height: 150px;" placeholder="post">          </textarea>      </div>      <div class="list-group">     <span style="float:left;display:inline-block;"><p style="font-size:15px">video file</p>    <input type="file" name="video" accept="video/*" /></span>     <p style="font-size:15px;margin-left:10%;width: 32px;display:inline-block;">or</p> 

image file

   </div>    <div class="listgroup"> category belongs <select name="cat"><?php foreach($cato $cat){ ?><option name="cat" value="<?php echo $cat->categoryid;?>"><?php echo $cat->categoryname;?></option><?php }?></select>       </div>     <div class="list-group" style="margin-top: 70px;margin-left: 35%;"> <button type="submit" style="width: 159px;height: 47px;line-height: 2.3;font-size: 17px;"  class="btn btn-success">submit</button>    </div>    </div>    </form>   </div> 

controller:

public function newpk(){        if($this->session->userdata('userid')){ $title=$this->security->xss_clean($this->input->post('title')); $post=$this->security->xss_clean($this->input->post('post'));     $cat=$this->security->xss_clean($this->input->post('cat'));       if($cat=="" || $post=="" || $title=="")     {      echo "required field cannot empty";     die();       }   $themepicid="";      $this->load->model('forum_model'); 

video part:

if(isset($_files['video']) && $_files['video']['size']>0){     $pktid=$this->idgenerator();       $pathh='assets/video/'; $themepicid=$this->session->userdata('userid'); $type= pathinfo($_files['video']['name'], pathinfo_extension); $pic=$themepicid; $themepicid=$themepicid.$pktid.".".$type;           move_uploaded_file($_files['video']['tmp_name'], $pathh.$themepicid);      $image="";     $this->forum_model->newp($title,$post,$image,$themepicid,$cat); // how forum likes 

image part:

    } else if(isset($_files['image']) && $_files['image']['size']>0){     $pathh='assets/images/'; $themepicid=$this->session->userdata('userid'); $type= pathinfo($_files['image']['name'], pathinfo_extension);     $pktid=$this->idgenerator();  $pic=$themepicid; $themepicid=$themepicid.$pktid.".".$type;               move_uploaded_file($_files['image']['tmp_name'], $pathh.$themepicid);      $image="";     $this->forum_model->newp($title,$post,$themepicid,$image,$cat);  } else{     $image="";    $this->forum_model->newp($title,$post,$image,$image,$cat);  }      redirect('index.php/forum','refresh');       }  else{  redirect('index.php/user','refresh');     }      }      } 

maybe video size larger max size upload config in php.ini

you can use upload library ci, it's easy use , prevent error

http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

if using upload lib of ci, dont forget config allowed types


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -