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 8203693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:38:47+00:00 2026-06-07T07:38:47+00:00

I am developing an website in php where user can upload csv file. after

  • 0

I am developing an website in php where user can upload csv file. after clicking ‘upload’ button, file is renamed and saved in the format ‘upload’.time(). I need to show the contents of the uploaded file just after uploading the file.
So far I have been able to upload file correctly and I have tested with a static filename and have been able to read csv file perfectly. but when I am trying to get recently uploaded file name just after uploading I am not getting anywhere. searched through the whole site but didn’t get any solution that worked for me.
I am using codeigniter 2.1.0 .

Controller file:

<?php     
class Csv_ci extends CI_Controller {

function is_logged() {
    $is_logged_in = $this->session->userdata('is_logged_in');
    if (!isset($is_logged_in) || $is_logged_in != true)
        return false;
    else
        return true;
}

function index() {
    if ($this->is_logged() == TRUE) {
        $this->load->model('Csv_model');

        if ($this->input->post('upload')) {
            $name = $this->Csv_model->do_upload();
            //print_r($name);
            if (isset($name)) {
                $filePath = "localhost/map_ci/csv/" . $name;
                //$filePath = './csv/bank_data.csv';
                $row = 1;
                if (($handle = fopen($filePath, "r")) !== FALSE) {
                    while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
                        $num = count($data);

                        $file_data[$row]['district_name'] = $data[1];
                        $file_data[$row]['bank_name'] = $data[2];
                        $file_data[$row]['area_name'] = $data[3];
                        $file_data[$row]['address'] = $data[4];
                        $row++;
                    }

                    fclose($handle);
                }
                $this->load->view('csvshow', array('file_data' => $file_data));
            }
        }
    }
    else $this->load->view('invalid_member');
     }
}

Model file:

 <?php

class Csv_model extends CI_Model {

var $gallery_path;
var $gallery_path_url;

function Csv_model() {
    parent::__construct();


    $this->gallery_path = realpath(APPPATH . '../csv');
    $this->gallery_path_url = base_url() . 'csv/';
}

function do_upload() {
    $config = array(
        'upload_path' => $this->gallery_path,
        'allowed_types' => 'text/csv|csv|text/x-comma-separated-values|text/comma-separated-values|application/x-csv|text/x-csv|text/csv|application/csv|',
        'max_size' => '5000',
        'file_name' => 'upload' . time()
    );


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

    if (!$this->upload->do_upload())
        echo $this->upload->display_errors();
    else {
        $file_info = $this->upload->data();
        $csvfilepath = "csv/" . $file_info['file_name'];
        $this->addfromcsv($csvfilepath);
        $filename = $file_info['file_name'];
        // print_r($filename);
        return $filename;
    }
} 
}

to retrieve file name I am doing file_info['file_name'].
Please help me find a solution.

Update:
My current problem has been solved after removing $csvfilepath = "csv/" . $file_info['file_name'];
$this->addfromcsv($csvfilepath);
these two lines from my code.Now its returning uploaded file name.yet to check whether fully working or not.

Update 2: code functioning well
thanks all for your help.

  • 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-06-07T07:38:48+00:00Added an answer on June 7, 2026 at 7:38 am

    You can return the concatenation of $config['upload_path'] & $config['file_name'] from do_upload() and use it to read the corresponding file.

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

Sidebar

Related Questions

I am developing a website in PHP that let the user to upload images
I'm developing a website in PHP and I'd like to give the user to
I am developing an advertisement site in PHP, the user can only list there
I am developing a website using PHP. I use Javascript/jquery to control/regulate user input.
I am developing a website selling gardening products using PHP and SQL. The user
I'm developing a website with PHP & MySQL where users can sign up. In
I'm developing website where user submit credentials using ajax,php and using POST method and
I'm developing a website where user's can create calendars and then add events to
I am developing a website in php. when a user types a page which
I am developing a video website ( PHP - MYSQL ), just like youtube,

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.