2011-12-14 61 views
0

我有一個codeigniter應用程序,每次進入該頁面時,都會顯示您沒有選擇要上傳的文件。我爲頁面顯示使用與文件句柄上傳相同的codeigniter功能。如何在頁面上第一次不顯示「您沒有選擇要上傳的文件」

我用ajax提交表單,所以我不能檢查$ _ SERVER [「REQUEST_METHOD」]

這是我的函數的一個片段:

if(!$this->upload->do_upload('userFile')) { // if there are errors uploading the file of if it's the first time on the page… 

    $content_data['album'] = $album; 

    echo "post go through?"; 

    // if the $_POST array is not empty display the error. That means that someone submitted the form without choosing a file 
    //if(isset($_POST['submit'])) { 
     $content_data['error'] = array('error' => $this->upload->display_errors()); 
    //} 

    $content_data['data'] = array('upload_data'=>$this->upload->data()); 
    $data['sess'] = $this->session; 
    $data['content'] = $this->load->view('member/addPhoto', $content_data, true); 
    $this->load->view('template/admin', $data); 
} else { // else there were no errors and we can resize and upload. 

} 
+1

顯而易見的問題是,爲什麼你使用相同的功能的頁面顯示處理文件上傳?有沒有我們不知道的約束?聽起來他們應該由不同的功能來處理,這將是解決問題最明顯的方法。 –

+0

這是因爲它是表單驗證使用相同功能的最佳做法,所以我認爲文件上傳類似......但現在你讓我思考。 – Catfish

回答

1

您可以檢查它是否是否提交之前進行上述操作

if ($this->input->post('userFile')) 
{ 
// Your code 
} 
+0

結合Ajay和Ryan的回答,我完成了她的工作。 – Catfish

相關問題