如何不第一次在页面上显示"You did not select a file to upload"



我有一个codeigniter应用程序,每次你去页面,它说你没有选择一个文件上传。对于页面显示,我使用与文件句柄upload相同的编码器函数。

我使用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.
}

您可以在执行上述操作之前检查是否提交

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

最新更新