Last active
July 24, 2018 10:23
-
-
Save vpadhariya/e55c8f9620236de6e55edcc956912f36 to your computer and use it in GitHub Desktop.
In any of core php project this function will help you create directory structure like follow PROJECT_ROOT/uploads/1_100 PROJECT_ROOT/uploads/101_200 PROJECT_ROOT/uploads/201_300 here is how to use it below will create PROJECT_ROOT/uploads/1_100 and return its path. createDir(1, "PROJECT_ROOT/uploads/"); Where PROJECT_ROOT is the hard path of th…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Creates a directory according to given id and parent dir path | |
* @params integer $id this id will decide which directory to return or create and then return | |
* @params string $parent this will decide what is the path of the directory. | |
*/ | |
function createDir($id, $parent) | |
{ | |
$nd_dirlimit = 100; | |
$mod = ceil($id / $nd_dirlimit) - 1; | |
$dirs = $mod * $nd_dirlimit + 1; | |
$dire = $dirs + $nd_dirlimit - 1; | |
$tempDir = $dirs.'_'.$dire; | |
if(!is_dir($parent.'/'.$tempDir)) | |
mkdir($parent.'/'.$tempDir,0775); | |
return $tempDir; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment