Question

Currently, This is the code I have in place to make a directory in my "members" folder dynamically every-time a user registers on my site.

        $directory = "../members/".$id;
        mkdir($directory, 0755);

The above code works fine but it doesn't name the folder with "0". Example:

When the folder is created in the members directory, It is named 15" in fact is should be named "000000000015".

Guys any idea how to achieve this in php.

Was it helpful?

Solution

use sprintf()

$directory = "../members/".sprintf('%012s',$id);
mkdir($directory, 0755);

http://php.net/sprintf

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top