php - 如何在用户注册时创建目录(PHP)

标签 php mysql

我正在尝试制作一个文件存储站点。我的用户可以登录并注册。现在我想做的是允许用户根据电子邮件在文件夹的不可公开访问的部分创建目录。 输入电子邮件:jdoe@yahoo.com,然后应创建一个具有该名称的目录。

假设我在 htdocs/testsite/。该目录应类似于 htdocs/files/jdoe@yahoo.com

此外,只有用户 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>

>

最佳答案

这可能有帮助:

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

有关 mkdir 的更多信息

mkdir 的语法:mkdir(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)

关于php - 如何在用户注册时创建目录(PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34354445/

相关文章:

python - 如何使用 MySQLdb 将整数和字符串值插入 MySQL?

php - 使用 where in 条件和最新时间​​戳连接两个 MySQL 查询

php - 将对象转换为数组

php - 四舍五入到最接近的分数(二分之一、四分之一等)

php - 在 MySQL 结果中创建可点击的链接

php - PHP 脚本可以在没有客户端请求的情况下在服务器上定期运行吗?

php - 重写 URL 以隐藏查询字符串

java - Mybatis如何运行sql "desc table"

php - 在 MySQL 和 Laravel 中预订

php - 如何防止 PHP 中的 SQL 注入(inject)?