Created
April 3, 2017 10:05
-
-
Save MehulBawadia/7ad6ef8efb1e2148c0f1b93af7a256ae to your computer and use it in GitHub Desktop.
A simple trait for creating a directory in PHP
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 | |
/** | |
* A simple trait for creating a directory. | |
* | |
* It can be used anywhere in/by the application.. It is specially | |
* recommended to use this for creating directories of user based | |
* folders at the time of user registration. | |
* | |
* @author IamCrazyD <[email protected]> | |
* @package \ (Root) | |
* @version 1.0.0 | |
*/ | |
trait CreateDirectoryIfNotExist | |
{ | |
/** | |
* Create the directory if the given path does not exist. | |
* | |
* @param string $path | |
* @return string | |
*/ | |
private function createDirectoryIfNotExists($path) | |
{ | |
$envType = env('APP_ENV'); | |
$hostingType = env('HOSTING_TYPE'); | |
if ($hostingType == 'shared') { | |
$path = base_path() . '/../public_html' . $path; | |
} | |
if ($hostingType == 'cloud') { | |
$path = public_path() . $path; | |
} | |
if (! file_exists($path)) { | |
mkdir($path, 0775, true); | |
} | |
return $path; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment