php - Can't read the files which was uploaed in COdeigniter upload folder -
using codeigniter i've upload files can't read files.
<?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 form , 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 upload form defeault * @access public * @return void */ function index() { $this->load->view('/upload/upload_form', array('error' => ' ' )); } /** * upload * @access public * @return void */ function do_upload() { //set config file //only doc,docx,xls,xlsx files can uploaded $config['upload_path'] = './upload/'; $config['allowed_types'] = '|doc|docx|xls|xlsx'; $config['max_size'] = '2000'; //load upload libraby 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 files , send right method * use convert 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)); } } ?> but file_exits shows false. in advance
to absolute filename, you may want use full_path instead of file_name. give absolute file system path file without building path yourself. currently, you're concatenating base_url file name not give file path, give url.
replace;
echo $filepath = $this->galary_path_url . $this->uploadfileinfo['upload_data']['file_name']; var_dump(file_exists($filepath)); with;
$fullpath = $this->uploadfileinfo['upload_data']['full_path']; echo $fullpath; var_dump(file_exists($fullpath));
Comments
Post a Comment