【问题标题】:I need to create a folder by using codeigniter without button click我需要使用 codeigniter 创建一个文件夹,而无需单击按钮
【发布时间】:2017-06-13 05:32:49
【问题描述】:

我需要创建一个文件夹来存储登录时的用户信息。一个登录按钮应执行 2 个操作。

他们是

  1. 登录
  2. 创建文件夹

我在 CODEIGNITER 中需要这个,请有人帮助我,我已经坚持了 4 周。

这是我的代码

<?php
ob_start();
defined('BASEPATH') OR exit('No direct script access allowed');


class LoginTwo extends CI_Controller
{

    function __construct() {
        parent::__construct();
        $this->load->model("login_model", "login");

    }
public function login()
{
    $username = $this->input->post("username");
    $password = $this->input->post("password");

    $isCorrect = $this->login->validate_user($username, $password);

    if($isCorrect)
    {
        // Start your user session

        $dirName = $username;
        $dirPath = "folder/".$dirName."/";

        if (!file_exists($dirPath)) {
            mkdir("folder/" . $dirName, 0777, true);
        }

        redirect("your user page");
    }
    else
    {
        redirect("homepage");
    }
}
}?>

【问题讨论】:

  • 你试过了吗???请出示您的代码。
  • 亲爱的 kishor,我添加了我已经尝试过的内容..我的项目主管强迫我在没有点击按钮的情况下创建这个文件夹,但我仍然是一名实习生,我很困惑..非常感谢您的帮助
  • 您的代码有错误吗?错误信息是什么?
  • 是的,这是错误严重性:通知消息:未定义索引:文件夹名称
  • 无论您尝试了什么,从该代码中我了解到您非常严重地误解了 codeigniter。您需要在登录功能中编写代码(在控制器中)。

标签: codeigniter


【解决方案1】:

尝试使用以下提到的解决方案。

$path = FCPATH.'/uploads/';
$new_directory = 'name';
mkdir($path.$name,0755,TRUE);

在这

  • First_Param:路径名:目录名称
  • Second_Param:模式:权限
  • 第三个参数:递归:允许创建嵌套目录

【讨论】:

    【解决方案2】:

    查看以下代码。您需要在此代码块中满足您的要求(如果您需要做更多的事情,您可以更改它)。

    你的控制器功能:

    public function login()
    {
        $username = $this->input->post("username");
        $password = $this->input->post("password");
    
        $isCorrect = $this->user_model->checkCredentials($username, $password);
    
        if($isCorrect)
        {
            // Start your user session
    
            $dirName = $username;
            $dirPath = "folder/".$dirName."/";
    
            if (!file_exists($dirPath)) {
                mkdir("folder/" . $dirName, 0777, true);
            }
    
            redirect("your user page");
        }
        else
        {
            redirect("homepage");
        }
    }
    

    【讨论】:

    • 亲爱的 Kishor 我根据您的建议编辑了我的代码。我在 CPanel 的根文件夹中准备了一个文件夹名称“文件夹”。但由于我的运气不好,它不起作用。我在我的最新代码上方进行了编辑。非常感谢你的努力。如果可以,请多做一些事情
    • 请先在本地主机上测试它,然后在实时服务器上工作。另外请根据您的要求修改代码,而不是按照我的建议。这只是不是全分辨率的方式。
    猜你喜欢
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 2016-02-25
    • 2014-08-28
    • 2022-10-15
    相关资源
    最近更新 更多