2014-10-27 83 views
0

我有一個按窗體上傳文件的問題。每次嘗試時,都會收到錯誤「文件類型不允許」。我使用HMVC模塊化擴展,我的控制器擴展了MX_Controller。Codeigniter模塊化HMVC擴展 - 無法上載文件

我已經試過$ var_dump($ _ FILES)從我的窗體視圖和結果是好的,但是當我嘗試在控制器中使用方法do_upload()它不工作。

有沒有人有任何想法?這裏是控制器:

Class Store_data extends MX_Controller 

{

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

function upload_pic() 
{ 
    //$data['item_id'] = $item_id; 
    $template = "bootstrap_theme"; 
    //$current_url = current_url(); 
    //$data['form_location'] = $current_url; 
    $data['view_file'] = "upload_pic"; 
    $this->load->module('template'); 
    $this->template->$template($data); 
} 

function do_upload() 
{ 
    //var_dump($_FILES); 
    $config['upload_path'] = './images/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = '10000'; 
    $config['max_width'] = '4024'; 
    $config['max_height'] = '4768'; 
    $this->load->library('upload', $config); 
    $this->upload->overwrite = true; 
    $this->upload->initialize($config); 

    if (! $this->upload->do_upload()) 
    { 
     $data['error'] = $this->upload->display_errors(); 
     $template = "bootstrap_theme"; 

     $data['view_file'] = "upload_pic"; 
     $this->load->module('template'); 
     $this->template->$template($data); 
    } 
    else 
    { 
     $data['upload_data'] = $this->upload->data(); 
     $template = "bootstrap_theme"; 
     $data['view_file'] = "upload_success"; 
     $this->load->module('template'); 
     $this->template->$template($data); 
    } 
} 

這裏是上傳表單視圖:

<?php echo $error;?> 
<?php echo form_open_multipart('store_data/do_upload');?> 
<input type="file" name="userfile" size="20" /> 
<br /><br /> 
<input type="submit" value="upload" /> 
</form> 

回答

0

我解決了這個問題。 我不得不取消註釋延長= php_fileinfo.dll在php.ini和評論;延長= php_mime_magic.dll

還是要謝謝你