我正在上传csv文件。它正确上传到该文件夹中。但是当我给出echo $ row ['adv_title']时,数据不显示。 这是我的控制器。我想显示标题
公共功能上传{
$config['upload_path'] = APPPATH.'/assets/upload/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '5000';
$replace='"';
$this->load->library('upload', $config);
$this->load->database();
if ( ! $this->upload->do_upload('file_name'))
{
$error=array('error' => $this->upload->display_errors());
$this->session->set_flashdata('msg_excel','Choose a .csv file to upload');
redirect(base_url().'admin/advertisement/adv');
}
else
{
$data=array('upload_data' => $this->upload->data());
$userfile=$data['upload_data']['file_name'];
$upload_data=$this->upload->data();
$this->load->library('csvreader');
$file=$upload_data['full_path'];
$file_name=$upload_data['userfile'];
$data=$this->csvreader->parse_file($file);
foreach($data as $row)
{
echo "hiii".$row['adv_title'];
}
}
问题是什么?
答案 0 :(得分:0)
试试这个 -
public function upload{
$config['upload_path'] = APPPATH.'/assets/upload/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '5000';
$replace='"';
$this->load->library('upload', $config);
$this->load->database();
if ( ! $this->upload->do_upload('file_name'))
{
$error=array('error' => $this->upload->display_errors());
$this->session->set_flashdata('msg_excel','Choose a .csv file to upload');
redirect(base_url().'admin/advertisement/adv');
}
else
{
$data=array('upload_data' => $this->upload->data());
$userfile=$data['upload_data']['full_path']; // file name
$upload_data=$this->upload->data();
$csv_file = fopen($userfile, "r");
// it will read csv file and convert into array
while (($emapData = fgetcsv($csv_file, 10000, ",")) !== FALSE)
{
echo "<pre>";
print_r($emapData);
}
fclose($file);
}