Codeigniter不会上传视频文件

时间:2014-04-06 15:07:18

标签: php codeigniter

我上传视频和图片的功能有问题。我可以上传图片而不是视频我不知道为什么。在控制器和表单的更多代码中。

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
    );
}

图像:

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 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 A Post</h3>
<div class="list-group" >
<input type="text" required name="title" id="title" class="form-control" placeholder="Title of the 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>

图像文件

   </div>
   <div class="listgroup">
To which category it belongs
<select name="cat"><?php foreach($cato as $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>

控制器:

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 be empty";
    die();

     }

 $themepicid="";

    $this->load->model('forum_model');

视频部分:

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 the forum likes

图片部分:

    }
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');
    }

    }

    }

1 个答案:

答案 0 :(得分:0)

也许您的视频尺寸大于最大尺寸上传配置在php.ini

您可以使用CI中的上传库,它易于使用并帮助您防止错误

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

如果您使用CI的上传库,请不要忘记配置允许的类型