简体   繁体   English

Codeigniter-PHP CSV文件上传

[英]Codeigniter - PHP CSV File uploading

when I run it on localhost my csv uploading file is completely fine but when I host it in the web it will get some error. 当我在localhost上运行它时,我的csv上传文件是完全可以的,但是当我在网络上托管它时,它将得到一些错误。 Its redirecting me to the csvindex.php I already check the columns in csv file 它已将我重定向到csvindex.php,我已经检查了csv文件中的列

Here's my importcsv(): 这是我的importcsv():

function importcsv($org, $course) {
    $data['addressbook'] = $this->users_model->get_addressbook();
    $data['error'] = '';    //initialize image upload error array to empty

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'csv';
    $config['max_size'] = '1000';

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



    // If upload failed, display error
    if (!$this->upload->do_upload()) {
        $data['error'] = $this->upload->display_errors();

        $this->load->view('csvindex', $data);
    } else {
        $file_data = $this->upload->data();
        $file_path =  './uploads/'.$file_data['file_name'];

        if ($this->csvimport->get_array($file_path)) {
            $csv_array = $this->csvimport->get_array($file_path);
            foreach ($csv_array as $row) {
                $insert_data = array(
                    'student_fname'=>$row['student_fname'],
                    'student_lname'=>$row['student_lname'],
                    'student_course'=>$row['student_course'],
                    'email'=>$row['email'],
                    'student_dept'=>$row['student_dept'],
                    'student_year'=>$row['student_year'],
                    'student_img'=>$row['student_img'],
                    'contact'=>$row['contact'],
                    'password'=>md5($row['password'])
                );
                $this->users_model->insert_csv($insert_data);
            }
            redirect('admin/colleges/show_students/'.$org.'/'.$course);
        } else 
            $data['error'] = "Error occured";
            $this->load->view('csvindex', $data);
        }

    } 

Here's my get_addressbook(): 这是我的get_addressbook():

function get_addressbook() {     
    $query = $this->db->get('tbl_students');
    if ($query->num_rows() > 0) {
        return $query->result_array();
    } else {
        return FALSE;
    }
}

Can someone help me with this please? 请有人帮我这个吗?

Check $file_path,the upload folder path in your server and check your upload folder permission – Sharmistha Das 2 hours ago 检查$ file_path,服务器中的上载文件夹路径,并检查您的上载文件夹权限– Sharmistha Das 2小时前

The error seems to be that your upload path either does not exist or does not have the right permissions. 错误似乎是您的上传路径不存在或没有正确的权限。

Best way to solve it is to go in via FTP or SSH to create the "uploads" folder in your codeigniter root. 解决此问题的最佳方法是通过FTP或SSH进入在codeigniter根目录中创建“ uploads”文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM