使用 codeigniter 我已经上传了一些文件,但我无法读取这些文件。
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Upload extends CI_Controller {
/**
* file Info
* @access priavte
* @var object
*/
private $uploadFileInfo;
private $galary_path_url;
/**
* load the form and url helper library
* load our new PHPExcel library
* contuctor
*/
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('excel');
$this->galary_path_url = base_url() . 'upload/';
}
/**
* load the upload form by defeault
* @access public
* @return void
*/
function index()
{
$this->load->view('/upload/upload_form', array('error' => ' ' ));
}
/**
* does the upload
* @access public
* @return void
*/
function do_upload()
{
//set up the config file
//only doc,docx,xls,xlsx files can be uploaded
$config['upload_path'] = './upload/';
$config['allowed_types'] = '|doc|docx|xls|xlsx';
$config['max_size'] = '2000';
//load the upload libraby with current config file
$this->load->library('upload', $config);
//if not uploaded
if ( ! $this->upload->do_upload())
{
echo $_FILES['userfile']['type'] ;
$error = array('error' => $this->upload->display_errors());
$this->load->view('/upload/upload_form', $error);
}
//uploaded successfully.
else
{
$this->uploadFileInfo = $data = array('upload_data' => $this->upload->data());
$this->load->view('/upload/upload_success', $data);
$this->pdfExport();
}
}
/**
* detect the files and send to the right method
* use the convert this to pdf file.
* @access public
* @return void Description
*/
public function pdfExport()
{
echo $filePath = $this->galary_path_url . $this->uploadFileInfo['upload_data']['file_name'];
var_dump(file_exists($filePath));
}
}
?>
但是 FILE_EXITS 显示错误。提前致谢