Welcome Guest, Not a member yet? Register   Sign In
Problem about Upload Filename into Database?
#1

[eluser]Unknown[/eluser]
Hi all,
i am a new CI. i has a problem about Upload file and save filename into Database.

Code:
Control
        class Blog extends Controller
{
// construction
    function Blog()
    {
    parent::Controller();
    $this->load->helper('date');
    $this->load->helper(array('form', 'url'));
    $this->load->library('upload');
    }

    function index()
    {
    $this->viewtopic();
    }

    function viewtopic()
    {
    $topic_list = $this->_topic_list();
    $data['body'] = $topic_list;
    $this->load->view('main' , $data);
    }

    function insert()
    {
    $blog_id = $_POST['blog_id'];
    $username = $_POST['username'];
    $comment = $_POST['comment'];
    $userfile = $this->input->post('userfile');
    //$userfile = $_POST['userfile'];
    $time = now();
        
    
    $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '50';
        $config['max_width'] = '100';
        $config['max_height'] = '100';

        $this->load->helper('form');
        $this->load->library('upload', $config);

    //echo "User:".$username."<br>Comment :".$comment."<br>Userfile :".$userfile."<br> Blog_id:".$blog_id;
    //exit();
        
    if(empty($comment) || empty($username))
    {
      show_error('Some field is blank!<br />Please <a href="[removed]history.back();">return</a>..');
    }
        
    $sql = "INSERT INTO `comments` (`blog_id` , `username` , `comment` , 'picture' , `time`) VALUES({$blog_id} , '{$username}' , '{$comment}' ,'{$userfile}' , {$time})";
    $this->db->query($sql);
        
    redirect('blog/viewblog/' . $blog_id);
    }
Problem :
1. I can not find filename for insert into SQL.
2. if i want another file. how i do?.

Thank.
#2

[eluser]Michael Wales[/eluser]
After a successful upload you may use the data() function to return information about the uploaded file. The one in particular you are after is:
Code:
$this->upload->data('file_name')

This can all be found at the bottom of the documentation.

I'm not sure what you mean on the second question.
#3

[eluser]Zeeshan Rasool[/eluser]
check acording to this sample.
$config['upload_path'] = './resources/admin_videos';
$config['allowed_types'] = 'mp3';
$config['max_size'] = '5000';

//$config['overwrite'] = false;

$this->upload->initialize($config);
$this->load->library('upload', $config);

if(!$this->upload->do_upload($video))
{
$error = array('error' => $this->upload->display_errors());
return $error;
}
else
{
$data = array('upload_data' => $this->upload->data());
$video_path =$data['upload_data']['file_name'];

}
$array = array(
'video_title' => $this->input->post('title'),
'video_path' => $video_path
);
$this->db->set($array);
$this->db->insert('help_video');




Theme © iAndrew 2016 - Forum software by © MyBB