【问题标题】:Codeigniter Unable to load the requested file: upload_form.phpCodeigniter 无法加载请求的文件:upload_form.php
【发布时间】:2017-09-22 02:07:27
【问题描述】:

CodeIgniter 无法加载请求的文件:upload_form.php

我遇到了这种类型的错误。

这是我正在上传的控制器文件。 控制器 上传.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); 
     } 
  } 

}

我在这里上传我的视图文件。 查看 上传表单.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(); ?>

【问题讨论】:

  • 试过用谷歌搜索这个吗?
  • 你的问题太宽泛了。有太多可能的答案。 SO 不是一个讨论平台。
  • 我编辑了这个问题,因为我无法在 3 天前提出新问题。

标签: php codeigniter file-upload


【解决方案1】:

我刚刚在 Google 上搜索了 Example for multi user role having Admin, user by using CodeIgniter,我得到了一个很好的结果集。

然后我注意到下面的链接是我从谷歌结果中得到的,这是你需要的。

http://www.w3programmers.com/making-multi-level-login-system-codeigniter/

注意:在发布到 SO 之前请花时间研究!!!!

【讨论】:

    【解决方案2】:

    第一步

    用户表

     ID  |  Name    | Email    | Password  | Role
     ==============================================
     1   |  abc     | abc@c.c  | ASDFAS    | user
     2   |  def     | def@c.c  | adfasdfsa | admin
    

    第二步

    登录控制器

    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

    【讨论】:

      【解决方案3】:

      为具有角色的管理员用户维护一个表。根据角色,您可以根据需要获取和显示数据或重定向到不同的页面。

      谢谢。

      【讨论】:

        【解决方案4】:

        将“Upload_form.php”重命名为“upload_form.php”

        【讨论】:

          猜你喜欢
          • 2012-05-25
          • 2018-07-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-01-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多