2015-12-18 36 views
0

我正在嘗試創建文件存儲站點。我的用戶可以登錄並註冊。現在我想要做的是允許用戶在基於電子郵件的文件夾的不可公開訪問的部分中創建一個目錄。 說出電子郵件:[email protected],那麼應該創建一個該名稱的目錄。如何在用戶註冊時創建目錄(PHP)

說我在htdocs/testsite /中。 dir應該像htdocs/files/[email protected]

此外,只有用戶jdoe應該能夠讀寫文件和目錄。 這裏是我的註冊代碼:

<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Registration Page</title></head> 
<body> 
    <?php 
    require('dbcon.php'); 
    if (isset($_POST['email'])) { 
     $fname = $_POST['fname']; 
     $lname = $_POST['lname']; 
     $email = $_POST['email']; 
     $password = $_POST['password']; 

     $fname = stripslashes($fname); 
     $fname = mysql_real_escape_string($fname); 

     $lname = stripslashes($lname); 
     $lname = mysql_real_escape_string($lname); 

     $email = stripslashes($email); 
     $email = mysql_real_escape_string($email); 

     $password = stripslashes($password); 
     $password = mysql_real_escape_string($password); 

     $query = "INSERT into `dropdriveusers` (fname,lname,email,password) VALUES ('$fname','$lname', '$email','" . md5($password) . "')"; 
     $endresult = mysql_query($query); 
     mkdir($_SESSION["email"]); 
     if ($endresult) { 
      echo "<h3>Account Registeration has been completed</h3><br/>Please click here to <a href='login.php'>Login</a>"; 
     } 
    } else { 
     ?> 

     <h1>Registration</h1> 
     <form name="rform" action="" method="post" onsubmit="Validate()"> 
      <input type="text" name="fname" placeholder="First Name" required /> 
      <input type="text" name="lname" placeholder="Lirst Name" required /><br> 
      <input type="email" name="email" placeholder="Enter your Email-ID" required /><br> 
      <input type="email" name="vmail" placeholder="Confirm your Email-ID" required /><br> 
      <input type="password" name="password" placeholder="Enter a password" required /><br> 
      <input type="password" name="passcheck" placeholder="Confirm your password" required /><br> 
      <input type="submit" name="submit" value="Register" /> 
     </form> 
    <?php } ?> 
</body> 

>

+0

是否要創建具有註冊用戶名的文件夾? –

+0

是的。它應該位於當前文件夾上方的目錄中。假設我在htdocs/testsite /中。 dir應該像htdocs/files/[email protected] – skyreon

+0

mkdir($ path。$ username)製作請參閱[mkdir](http://php.net/mkdir)不要忘記設置文件夾的權限(讀寫等) –

回答

0

可能這會有所幫助:

<?php 
$dirname = "htdocs/files/".$email; 
mkdir($dirname); 
?> 

更多infor關於mkdir

語法的mkdirmkdir(path,mode,recursive,context)

path --> Required. Specifies the name of the directory to create 
mode --> Optional. Specifies permissions. By default, the mode is 0777 (widest possible access). 

The mode parameter consists of four numbers: 

The first number is always zero 
The second number specifies permissions for the owner 
The third number specifies permissions for the owner's user group 
The fourth number specifies permissions for everybody else 

Possible values (to set multiple permissions, add up the following numbers): 

1 = execute permissions 
2 = write permissions 
4 = read permissions 

recursive --> Optional. Specifies if the recursive mode is set (added in PHP 5) 
context --> Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream (added in PHP 5) 
+1

由於mkdir默認爲0777,因此請務必按照要求更改模式。 – booota

+0

@booota我剛剛從我提供的鏈接複製:) –

+0

:)這只是一個建議,因爲我們大多不希望我們的目錄是全局可讀/可寫/可執行文件。 – booota

相關問題