上传csv文件时会在CodeIgniter

时间:2017-06-10 10:06:27

标签: php codeigniter csv

我正在上传csv文件并希望显示它,但它显示了其他内容。这是输出:

image

这是我的代码 控制器中的Upload.php

    <?php
if (!defined('BASEPATH'))
  exit('No direct script access allowed');

class Upload extends CI_Controller {

     public function __construct()
   {
        parent::__construct();
   }

  //if index is loaded
    public function index() {
        //load the helper library
        $this->load->helper('form');
    $this->load->helper('url');
        //Set the message for the first time
        $data = array('msg' => "Upload File");

    $data['upload_data'] = '';

        //load the view/upload.php with $data
        $this->load->view('upload', $data);


    }


}

这是我的另一个控制器 Upload_file.php

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Upload_file extends CI_Controller{


  function __construct()
  {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }


    function upload_it() {
        //load the helper
        $this->load->helper('form');

        //Configure
        //set the path where the files uploaded will be copied. NOTE if using linux, set the folder to permission 777
        $config['upload_path'] = 'application/views/';

    // set the filter image types
        $config['allowed_types'] = 'gif|jpg|png|csv';

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

    $this->upload->initialize($config);

    $this->upload->set_allowed_types('*');

        $data['upload_data'] = '';

        //if not successful, set the error message
        if (!$this->upload->do_upload('userfile')) {
            $data = array('msg' => $this->upload->display_errors());

        } else { //else, set the success message
            $data = array('msg' => "Upload success!"); 

      $data['upload_data'] = $this->upload->data();

        }

        //load the view/upload.php
        $this->load->view('upload', $data);

    }

}

编辑** 这是我的观点 ** upload.php的

    <html> 
    <head>
           <!-- <style type="text/css">
            ::selection{ background-color: #E13300; color: white; }
            ::moz-selection{ background-color: #E13300; color: white; }
            ::webkit-selection{ background-color: #E13300; color: white; }
            body {
                background-color: #fff;
                margin: 40px;
                font: 13px/20px normal Helvetica, Arial, sans-serif;
                color: #4F5155;
            }
            a {
                color: #003399;
                background-color: transparent;
                font-weight: normal;
            }
            h1 {
                color: #444;
                background-color: transparent;
                border-bottom: 1px solid #D0D0D0;
                font-size: 19px;
                font-weight: normal;
                margin: 0 0 14px 0;
                padding: 14px 15px 10px 15px;
            }
            code {
                font-family: Consolas, Monaco, Courier New, Courier, monospace;
                font-size: 12px;
                background-color: #f9f9f9;
                border: 1px solid #D0D0D0;
                color: #002166;
                display: block;
                margin: 14px 0 14px 0;
                padding: 12px 10px 12px 10px;
            }
            #body{
                margin: 0 15px 0 15px;
            }
            p.footer{
                text-align: right;
                font-size: 11px;
                border-top: 1px solid #D0D0D0;
                line-height: 32px;
                padding: 0 10px 0 10px;
                margin: 20px 0 0 0;
            }
            #container{
                margin: 10px;
                border: 1px solid #D0D0D0;
                -webkit-box-shadow: 0 0 8px #D0D0D0;
            }-->
        </style>
    </head>
    <body>
       <!-- <div id="container">
            <h1>How to upload file in Codeigniter</h1>-->
            <div id="body">



<code><?php echo $msg;?></code>


<code>
<?php if($upload_data != ''):?>
<?php var_dump($upload_data);?>

</code>

<?php endif;?>

<?php echo form_open_multipart('Upload_file/upload_it');?>

<input type="file" name="userfile" size="20" />

<br /><br />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>


<input type="submit" value="upload" class="btn btn-success" />

</form>



 </div>
        </div>
    </body>
</html>

0 个答案:

没有答案