2015-11-04 89 views
0

我發現這麼多問題都有同樣的錯誤。但這些答案並沒有清除我的錯誤,仍然錯誤仍然您沒有選擇一個文件上傳。但圖像上傳

當我嘗試上傳圖像。這個錯誤出現

沒有選擇要上傳的文件

圖像在正確的位置上傳..

控制器

class image extends CI_Controller { 

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

    $this->load->helper(array('form', 'url')); 

    $this->load->library('session'); 

    $this->load->library('layout'); 

    $this->load->model('admin_m'); 

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

    } 

    function projects_more() { 

    $config['upload_path'] = './uploads/'; 

    $config['allowed_types'] = 'gif|jpg|png'; 

    $config['max_size'] = '100000'; 

    $config['max_width'] = '102400'; 

    $config['max_height'] = '76800'; 


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

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

    if (!$this->upload->do_upload('photo')) { 

     $error = array('error' => $this->upload->display_errors()); 

     $this->layout->view('home_page', $error); 

    } else { 

     $data = array('upload_data' => $this->upload->data()); 
     $data1 = $this->upload->data(); 
     $image = $data1['file_name']; 
     $project = $this->input->post('project'); 


     $content= $this->input->post('content'); 

     $this->admin_m->projects_more($image,$project,$content); 
     redirect('image/projects_more'); 

    } 
    } 
} 

我的看法頁面

projects1.php

<?php echo form_open_multipart('image/projects_more'); ?> 

<table> 

<tr> 

<td><input type="file" name="photo" id="photo" size="20"></td> 

</tr> 

</table> 

<input type="submit" name="submit" value="Submit"> 

<?php echo form_close(); ?> 
+1

請將您的視圖文件了。 –

+3

'你沒有選擇一個文件上傳'不是一個PHP錯誤。 –

回答

0

對不起。這是我的錯誤。函數projects_more第一次上傳圖像,並在函數結束時重定向到沒有要上傳文件的相同函數。第一次它上傳圖像,第二次它不會。因爲浪費你的時間。感謝丹尼斯B.

現在我重定向到索引功能,顯示視圖頁面,選擇下一個圖像及其細節..

1

試試這個:

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

$config = array 
(
'upload_path' => 'yourUploadPath', 
'allowed_types' => 'png|jpg|gif', 
); 
$this -> upload -> initialize($config); 
$this -> upload -> do_upload('photo'); 

如果你想將文件上傳到uploads文件夾是有同一文件夾applicationsystem文件夾,你的上傳路徑應該是這樣的:

'upload_path' => 'uploads', 

順便說一句,您不需要逐頁加載庫和幫助程序,您可以使用autoload.php文件夾下的application/config文件夾。

+0

圖像上傳沒有問題。圖像上傳成功。但是還顯示一條錯誤消息。我如何避免該錯誤消息。 –

+0

刪除這部分代碼: if(!$ this-> upload-> do_upload('photo')){ $ error = array('error'=> $ this-> upload-> display_errors()) ; –

相關問題