注册时在服务器上创建文件夹 [英] Create Folder On Server Upon Registration

查看:36
本文介绍了注册时在服务器上创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮助我.

I wonder whether someone could help me please.

我一直在寻找有关如何在用户注册"时自动在我的服务器中创建文件夹的教程或示例,更具体地说:

I've been trying to find a tutorial or examples of how to automatically create a folder in my server upon 'user registration', to be more specific:

顶级文件夹称为用户注册的用户名",其中的下一级文件夹称为图像",其中的文件夹称为拇指".

The top level folder to be called the 'username' that the user registered with, the next level folder within this to be called 'images', and the folder within that, to be called 'thumbs'.

正如我所说,我一直在寻找可以告诉我如何做到这一点的东西,但我没有运气.

As I said I've been searching for something that can show me how to do this, and I've not had any luck.

我只是想知道是否有人可以指导我使用一些教程或示例来帮助我实现这一目标.理想情况下,如果我可以将其放入一个 PHP 脚本中,该脚本可以在用户完成注册时自动运行,那就太好了.

I just wondered whether someone could perhaps guide me to some tutorial or example that I could use to help me achieve this. Ideally, it would be great if I could get this into a PHP script which could be run automatically when the user completes registration.

非常感谢

推荐答案

基本上是利用了mkdir,但是你可能想把它包装成一个它自己的类,这样你以后就可以更好地将它绑定到用户名或 ID 以摆脱具体的路径名:

It's basically making use of mkdir, however you might want to wrap this into a class of it's own so you can later on better bind it to a user-name or ID to move away from concrete pathnames:

$userDir = new UserDir($pathToUserDir);
$userDir->createImageDirectory();

class UserDir extends SplFileInfo
{
    public function createThumbDirectory()
    {
        return $this->createSubdirectory('thumb');
    }
    public function createImageDirectory()
    {
        return $this->createSubdirectory('image');
    }
    private function createSubdirectory($name)
    {
        $path = $this->getPathname();
        $dir = $path . PATH_SEPARATOR . $name;
        return mkdir($dir);
    }
}

然后您可以在中央位置使用错误条件检查来扩展它,以便在您的应用程序中轻松使用.

You can then extend this with error condition checking in a central place, so it's easy to use in your application.

这篇关于注册时在服务器上创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆