Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6739991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:33:11+00:00 2026-05-26T11:33:11+00:00

I am trying to put the file path to database, I already uploaded the

  • 0

I am trying to put the file path to database, I already uploaded the file but I don’t know how to get the path of the file to put it in the database?

Here is the controller:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class dogo extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('insert_article');
    }   
    public function index()
    {

    $this->load->view('dogo/dashboard.php');

    }
    //add new post to database including uploading image
    public function new_post()
    {

    //used for the dropdown menu (category)
    $this->load->model('dogo_cat');
    $data['categores_dropdown'] = $this->dogo_cat->get_categories();    

    //form validation
    $this->load->library('form_validation');//load the validation library

    $this->form_validation->set_rules('title', 'title of the post', 'required');
    $this->form_validation->set_rules('text', 'text of the post', 'required');
    //$this->form_validation->set_rules('image', 'image of the post', 'required');
    $this->form_validation->set_rules('category', 'category of the post', 'required');  

    //the form validation condition
    if($this->form_validation->run() == FALSE){
        //error
        //$this->view_data
        $this->load->view('dogo/new_post.php', $data);      
    }else{

        //no error in the form
        $title = $this->input->post('title');
        $text = $this->input->post('text');
        $category = $this->input->post('category');
        $publish = $this->input->post('publish');
        //$img_nw = $this->input->post('img_nw');
        //$img_nw = $this->input->post('img_nw');
        $image_file = $this->input->post('image_file');



        //uploading
        $this->load->model('upload_new_post');
        if($this->input->post('upload')){
        $this->upload_new_post->do_upload();

        //$this->insert_article->insert_new_post($title, $category, $img_nw, $text, $source, $publish);

        $data['images'] = $this->upload_new_post->get_images();

        echo "title of the post: " . $title . "<br /> and the text of the post " . $text . "<br /> and category is: " . $category . "<br /> and publish is: " .$publish . "<br /> and image: <pre>" . $do_upload ."</pre>";




            //echo $img_nw;


            $this->load->view('dogo/new_post.php', $data);              


        }



    }






    }   
}

And here is the model to upload it:

    <?php
class upload_new_post extends CI_Model{
    // retreive categories 
    var $file_path;
    var $file_path_url;

        function __construct() {
        parent::__construct();
            $this->file_path = realpath(APPPATH . '../post_data/images');
            $this->file_path_url = base_url().'post_data/images/';
    }

    function do_upload(){
        $config=array(
        'allowed_types' => 'jpg|jpeg|gif|png',
        'upload_path' => $this->file_path,
        'max_size' => 2000 
        );


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

        $image_data = $this->upload->data();

        $config = array(
            'source_image' => $image_data['full_path'],
            'new_image' => $this->file_path . '/thumbs',
            'maintain_ration' => true,
            'width' => 150,
            'height' => 150
        );

        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
    }

    function get_images(){
        $files = scandir($this->file_path);
        $files = array_diff($files, array('.', '..', 'thumbs'));

        $images = array();

        foreach ($files as $file){
            $images [] = array(
                'url' => $this->file_path_url . $file,
                'thumb_url' => $this->file_path_url . 'thumbs/' .$file
            );

        }
        return $images;
    }

}       

And here the model to insert query:

    <?php
class Insert_article extends CI_Model{

    //insert new post
    function __construct() {
        parent::__construct();
    }   

    function insert_new_post($title, $category, $img_nw, $text, $source, $publish)
    {
        $query_insert = "INSERT INTO hs_news_nw (idcat_nw, idsc_nw, idusr_nw, title_nw, img_nw, text_nw, active_nw, totalview_nw, date_nw) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
        $this->db->query($query_insert, array($category, $source, 1, $title, $img_nw, $text, 1, 1000, '2011-10-12 02:01:24'));
    }
}       
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:33:11+00:00Added an answer on May 26, 2026 at 11:33 am

    You should return $image_data from do_upload() function in your upload_new_post model.

    $image_data = $this->upload->data();
    ..
    ..
    return $image_data;
    

    $image_data contains all the info about uploaded file including file name and path (do a print_r). Then you can pass it onto Insert_article model from your controller to store in database.

    For reference:

    http://codeigniter.com/user_guide/libraries/file_uploading.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to put a file path in javascript. it is a pain \ is
I'm trying to put into XML-file some data. Here is the code: @Test public
I'm trying to open a file with fopen, but I don't want a static
I am trying to put a PSD file on my form using Microsoft report
I'm trying to put a 3D model into a PDF file. When I load
Alright, I'm trying to read a comma delimited file and then put that into
I'm trying to connect to an access database from a php script using ODBC.
Im tired of trying to put this working :( So, here is my problem:
Sorry for asking a question about something I don't know much about, but I've
I'm trying to add an header file to dev-C++ but when I compile it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.