2017-04-25 64 views
-4

無法加載所需的文件:upload_form.php笨無法加載所需的文件:upload_form.php

我得到這種類型的錯誤遇到。

這是我上傳的控制器文件。 控制器 upload.php的

class Upload extends CI_Controller 

{

public function __construct() 
    { 
    parent::__construct(); 
    $this->load->helper(array('form', 'url')); 
    } 

    public function index() 
     { 
    $this->load->view('upload_form', array('error' => ' ')); 
    } 

    public function do_upload() 
    { 
    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|jpeg|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('userfile')) 
    { 
     $error = array('error' => $this->upload->display_errors()); 
     $this->load->view('upload_form', $error); 
    } 

    else 
    { 
     $data = array('upload_data' => $this->upload->data()); 
     $this->load->view('upload_success', $data); 
    } 
    } 

}

我在這裏上傳我的視圖文件。 查看 Upload_form.php

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

試過在谷歌搜索這個嗎? – Akintunde007

+1

你的問題太廣泛了。有太多可能的答案。 SO不是一個討論平臺。 –

+0

我編輯了這個問題,因爲我無法在3天前提出新的問題。 –

回答

1

步驟-1

用戶表

ID | Name | Email | Password | Role 
============================================== 
1 | abc  | [email protected] | ASDFAS | user 
2 | def  | [email protected] | adfasdfsa | admin 

步驟2

登錄控制器

public function index() 
{ 
    if($this->isLoggedin()){ redirect(base_url().'login/dashboard');} 
    $data['title']='Login Boiler Plate'; 
    if($_POST) 
    { 
     $config=array(
      array(
       'field' => 'username', 
       'label' => 'Username', 
       'rules' => 'trim|required' 
      ), 
      array(
       'field' => 'password', 
       'label' => 'Password', 
       'rules' => 'trim|required' 
      ) 
     ); 
     $this->form_validation->set_rules($config); 
     if ($this->form_validation->run() == false) { 
      // if validation has errors, save those errors in variable and send it to view 
      $data['errors'] = validation_errors(); 
      $data['csrf'] = array(
       'name' => $this->security->get_csrf_token_name(), 
       'hash' => $this->security->get_csrf_hash() 
      ); 
      $data['title']='Login Boiler Plate'; 
      $this->load->view('login',$data); 
     } else { 
      // if validation passes, check for user credentials from database 
      $data = $this->security->xss_clean($_POST); 
      $user = $this->Login_model->checkUser($data); 
      if ($user) { 
      // if an record of user is returned from model, save it in session and send user to dashboard 
       $this->session->set_userdata($user); 

       redirect(base_url() . $user['role']); 
      } else { 
      // if nothing returns from model , show an error 
       $data['errors'] = 'Sorry! The credentials you have provided are not correct'; 
       $data['csrf'] = array(
        'name' => $this->security->get_csrf_token_name(), 
        'hash' => $this->security->get_csrf_hash() 
       ); 
       $data['title']='Login Boiler Plate'; 
       $this->load->view('login',$data); 
      } 
     } 

    } 
    else 
    { 
     $data['csrf'] = array(
      'name' => $this->security->get_csrf_token_name(), 
      'hash' => $this->security->get_csrf_hash() 
     ); 
     $this->load->view('login',$data); 
    } 

} 

要查看模型和形式啓動讀Codeigniter 3.x Login with Form Validation -Boiler plate

0

爲具有角色的管理員用戶維護一張表。根據角色,您可以根據需要獲取並顯示數據或重定向到不同的頁面。

謝謝。

0

將「Upload_form.php」重命名爲「upload_form.php」