csv上传不起作用 [英] csv uploaded not working
本文介绍了csv上传不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在上传csv文件。它是在文件夹中正确上传。但是当给出echo $ row ['adv_title']时,数据不显示。
这是我的控制器。我想显示标题
i am uploading csv file.It is correctly upload in the folder. but data is not displaying when i given echo $row['adv_title']. this my controller.I want to display the title
public function upload {
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']['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'];
}
}
问题?
推荐答案
尝试此 -
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']['file_name']; // 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);
}
这篇关于csv上传不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文