Create Folder On Server Upon Registration

时光毁灭记忆、已成空白 提交于 2019-12-01 08:30:34

问题


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.

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.

Many thanks


回答1:


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.




回答2:


use mkdir.
source: http://php.net/manual/en/function.mkdir.php complete description given




回答3:


To create folders with php you can use the function mkdir (which stands for "make directory").

http://php.net/manual/de/function.mkdir.php




回答4:


You could use something like exec() to run a system command like mkdir http://php.net/manual/en/function.exec.php



来源:https://stackoverflow.com/questions/8646073/create-folder-on-server-upon-registration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!