在PHP ci框架中上传文件既不显示错误也不显示结果


uploading file in php ci framework neither show errors nor show result

我看了很多视频,参考了CI用户指南,但是无法发现错误。当文件从表单提交时,它将程序流发送到下面的uploadImage()方法。请给我指路。谢谢你

我的代码:
     public function uploadImage()
    {
        $config['upload_path'] = './files/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $this->load->library('upload');
        $this->upload->initialize($config);
        if(!$this->upload->do_upload())
        {
        $this->load->view('upload');
        }
        else
        {
        $this->upload->display_errors();
        }
    }

我不知道你想做什么,请看看下面可能有帮助。

  public function uploadImage()
    {
        $config['upload_path'] = './files/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
//load upload class library
        $this->load->library('upload', $config);

    //$this->upload->do_upload('filename') will upload selected file to destiny folder
    if (!$this->upload->do_upload('filename'))
    {
        // case - failure
        $upload_error = array('error' => $this->upload->display_errors());
        $this->load->view('edit', $upload_error);
    }
    else
    {
        // case - success
        //callback  returns an array of data related to the uploaded file like the file name, path, size etc

    $upload_data = $this->upload->data();
$data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' .$upload_data['file_name']. '</strong> was successfully uploaded!</div>';
             //$this->load->view('edit_profile', $data);

        redirect(base_url("Display_somepage/index"));
        }

//下面的代码可能对调试

有帮助
echo $this->image_lib->display_errors();

我认为这是一个语法错误,注意箭头。

public function uploadImage()
{
    $config['upload_path'] = './files/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';
    $this->load->library('upload');
    $this->upload->initialize($config);
    if($this->upload->do_upload('YOUR_FILE_INPUT_NAME'))  <=========== HERE
    {
     $this->load->view('upload');
    }
    else
    {
     $this->upload->display_errors();
    }
}

基本上,你告诉它加载视图时,上传成功,否则显示错误,如果操作失败,而不是相反。