Codeigniter non uploada le img o video nel DB

Jakub Lemiszewski

Utente Attivo
5 Dic 2013
119
1
0
Salve, sto cercando con il seguente codice di fare in modo che nei post del mio forum si possa uploadare un img o video ma non funziona non mi uploada niente. Se potete aiutarmi grazie.
PHP:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* 
 * Description: Login model class
 */
class forum_model extends CI_Model{
	function __construct(){
		parent::__construct();
	}

	function getcategories(){
	
		$query=$this->db->get('category');
		if($query->num_rows>=1)
			return $query->result();
		return NULL;
	}


	function categoryexists($id){

		$this->db->where('categoryid',$id);
		$this->db->from('category');
		$query=$this->db->get();
		if($query->num_rows>=1)
			return true;
		return false;

	}
	function getnumberofposts($id){


		$this->db->where('categoryid',$id);
		$query=$this->db->get('forum');
		return $query->num_rows;
	}

	function getcategorynextposts($id,$number){
		$this->db->where('categoryid',$id);
		$query=$this->db->get('forum');
		$k=NULL;


		if($query->num_rows==0)
			return $k;


		$i=0;
$j=0;
$result=$query->result();



foreach($result as $row){
	if($i>=$number && $i<=$number+15){
		$k[$j]=$row;
		$k++;
	}

$i++;

}

return $k;

}

function latestposts(){

$this->db->from('forum');
$this->db->order_by('forumid','DESC');
$query=$this->db->get();
$s=NULL;
$i=0;
$result=$query->result();
foreach($result as $row){

if($i==11)
	break;
$s[$i]=$row;
$i++;
}





return $s;

}



function popularposts(){
	$this->db->from('forum');
	$this->db->order_by('viewed','DESC');
	$query=$this->db->get();
	$result=$query->result();
$s=NULL;
$i=0;
foreach($result as $row){

if($i==16)
	break;
$s[$i]=$row;
$i++;
}




return $s;

}


function postexists($id){
	$this->db->where('forumid',$id);
	$query=$this->db->get('forum');
	echo $query->num_rows;
	if($query->num_rows>=1)
		return true;
	return false;



}


function viewpost($id){
	$this->db->where('forumid',$id);
	$query=$this->db->get('forum');

	$row=$query->row();
	$row->viewed+=1;
	$this->db->where('forumid',$id);
	$this->db->update('forum',$row);

	$this->db->where('forumid',$id);
	$query=$this->db->get('forum');



	return $query->row();




}

function getkomments($id){
	$this->db->where('forumid',$id);
	$this->db->from('forumcomment');
	$this->db->join('user','forumcomment.userid=user.userid');

	$query=$this->db->get();
	if($query->num_rows>=1)
		return $query->result();
	return NULL;



}

function insertcomment($userID,$id,$comment){
	$data=array(
		'userid'=>$userID,
		'forumid'=>$id,
		'comment'=>$comment

		);
	$this->db->insert('forumcomment',$data);

return 1;

}

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


}

}
il form collegato:
Codice:
<div class="col-lg-2" style="width:72%;min-width:300px;min-height:300px;border-right:1px solid #ccc;height:auto;margin-left: 15%;
border-left: 1px solid #ccc;">


<!--Give the possibility to uplad img/video -> 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 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/mp4,video/x-m4v,video/*" /></span>
<p style="font-size:15px;margin-left:10%;width: 32px;display:inline-block;">OR</p>

<span style="float:right;display:inline-block;"><p style="font-size:15px">Image File</p> <input type="file" name="image" accept="image/*" /></span>

</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>
 
Ultima modifica:

Discussioni simili