Welcome Guest, Not a member yet? Register   Sign In
problem to Uploading and save image and video
#1

Hello,

I have to use CI_VERSION = '3.1.2';

I have to face problem to uploading video and images below is my code.

Controller file


PHP Code:
class Users extends CI_Controller
{
 
   function  __construct() {
 
       parent::__construct();
 
       $this->load->model('user');
 
   }
 
   
    function add
(){
 
       if($this->input->post('userSubmit')){
 
           
            
//Check whether user upload picture
 
           if(!empty($_FILES['picture']['name'])){
 
               $config = array();
 
           $config['upload_path'] = './uploads/';
 
           $config['allowed_types'] = 'gif|jpg|png';
 
           $config['max_size'] = '100';
 
           $config['max_width'] = '1024';
 
           $config['max_height'] = '768';
 
           $config['max_filename'] = '100';

 
           $this->load->library('upload'$config);
 
               $this->upload->initialize($config);
 
               if($this->upload->do_upload('picture')){
 
                   
                    $uploadData 
$this->upload->data();
 
                   $picture $uploadData['file_name'];
 
               }else{

 
                   $picture 'nothing';
 
               }
 
               
                
            
}else{
 
               $picture 'Noooo';
 
           }
 
           
            
//Prepare array of user data
 
           $userData = array(
 
               'name' => $this->input->post('name'),
 
               'email' => $this->input->post('email'),
 
               'picture' => $picture
            
);
 
           
            
//Pass user data to model
 
           $insertUserData $this->user->insert($userData);
 
           
            
//Storing insertion status message.
 
           if($insertUserData){
 
               $this->session->set_flashdata('success_msg''User data have been added successfully.');
 
           }else{
 
               $this->session->set_flashdata('error_msg''Some problems occured, please try again.');
 
           }
 
       }
 
       //Form for adding user data
 
       $this->load->view('users/add');
 
   }


Model file code 

PHP Code:
class User extends CI_Model{
 
   function __construct() {
 
       $this->tableName 'user';
 
       $this->primaryKey 'id';
 
   }
 
   
    public 
function insert($data = array()){
 
       if(!array_key_exists("created",$data)){
 
           $data['created'] = date("Y-m-d H:i:s");
 
       }
 
       if(!array_key_exists("modified",$data)){
 
           $data['modified'] = date("Y-m-d H:i:s");
 
       }
 
       $insert $this->db->insert($this->tableName,$data);
 
       if($insert){
 
           return $this->db->insert_id();
 
       }else{
 
           return false   
        
}
 
   }



View File

PHP Code:
<?php echo $this->session->flashdata('success_msg'); ?>
<?php 
echo $this->session->flashdata('error_msg'); ?>
<form role="form" method="post" enctype="multipart/form-data">
    <div class="panel">
        <div class="panel-body">
            <div class="form-group">
                <label>Picture</label>
                <input class="form-control" type="file" name="picture" />
            </div>
            <div class="form-group">
                <label>Name</label>
                <input class="form-control" type="text" name="name" />
            </div>
            <div class="form-group">
                <label>Email</label>
                <input class="form-control" type="text" name="email" />
            </div>
             <div class="form-group">
                <input type="submit" class="btn btn-warning" name="userSubmit" value="Add">
            </div>
        </div>
    </div>
</form> 

any changes need in config?

Please help me its urgent.

Thanks in advance.
Reply
#2

Hi,

What is the problem exactly ?
A good decision is based on knowledge and not on numbers. - Plato

Reply




Theme © iAndrew 2016 - Forum software by © MyBB