2017-06-13 55 views
0

我需要創建用戶信息存儲在登錄一個文件夾中創建一個文件夾。一個登錄按鈕應執行2個操作。我需要用笨而不按一下按鈕

他們

  1. 登錄
  2. 創建文件夾

我需要這個CI中,請幫助我的人,我一直在堅持這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"); 
    } 
} 
}?> 
+0

你嘗試過什麼???請顯示你的代碼。 – kishor10d

+0

親愛的基肖爾我加我曾嘗試yet..My項目主管迫使我沒有點擊一個按鈕來創建此文件夾,還是我一個實習生上午confused..help將高度讚賞 – Dushee

+0

是您的代碼得到任何錯誤?什麼是錯誤信息? – Imran

回答

0

嘗試使用下面提及的解決方案。

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

在這種

  • FIRST_PARAM:路徑:模式:權限
  • 第三帕拉姆:遞歸:目錄
  • SECOND_PARAM的名稱允許嵌套目錄的創建
0

看看下面的代碼。你需要在這個代碼塊中適合你的需求(如果你還需要做更多的事情,你可以改變它)。

您控制器功能:

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"); 
    } 
} 
+0

親愛的Kishor我根據你的建議編輯我的代碼。我在CPanel的根文件夾中準備文件夾名稱「文件夾」。但是對於我的運氣不好,這並不奏效。我已經編輯了上面我最新的代碼。非常感謝您的努力。如果可以,請做更多的工作 – Dushee

+0

請首先在localhost上測試它,然後在活動服務器上運行。還請根據您的要求修改代碼,而不是根據我的建議。這只是不完整的解決方案。 – kishor10d

相關問題