php - How to retrieve recently uploaded file name in codeigniter -


i developing website in php user can upload csv file. after clicking 'upload' button, file renamed , saved in format 'upload'.time(). need show contents of uploaded file after uploading file. far have been able upload file correctly , have tested static filename , have been able read csv file perfectly. when trying uploaded file name after uploading not getting anywhere. searched through whole site didn't solution worked me. 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 doing file_info['file_name']. please me find solution.

update: current problem has been solved after removing $csvfilepath = "csv/" . $file_info['file_name']; $this->addfromcsv($csvfilepath); these 2 lines code.now returning uploaded file name.yet check whether working or not.

update 2: code functioning help.

you can return concatenation of $config['upload_path'] & $config['file_name'] do_upload() , use read corresponding file.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -