示例#1
0
 public static function go($fileName, $content, $fileLocation, $force)
 {
     //----------------------------------------------------------
     //init var
     //----------------------------------------------------------
     $chk = array("bool" => true, "func" => "createFile");
     //----------------------------------------------------------
     $chk = GenFun::error_CHK(array('fileName' => $fileName, 'content' => $content));
     //----------------------------------------------------------
     if (!$chk['bool']) {
         return $chk;
     }
     //----------------------------------------------------------
     $defaultLocation = $_SERVER["DOCUMENT_ROOT"];
     //----------------------------------------------------------
     if (substr($defaultLocation, -1) != "/") {
         $defaultLocation .= "/";
     }
     //----------------------------------------------------------
     $fileLocation = is_null($fileLocation) ? $defaultLocation : $defaultLocation . $fileLocation;
     //----------------------------------------------------------
     if (!is_dir($fileLocation)) {
         if ($force) {
             $fileLocation = GenFun::getPathFromFileLocation($fileLocation);
         }
         //------------------------------------------
         if (!is_dir($fileLocation)) {
             $chk['bool'] = false;
             $chk['message'] = $fileLocation . " directory does not exist";
             return $chk;
         }
     }
     //----------------------------------------------------------
     $file = $fileLocation . $fileName;
     //----------------------------------------------------------
     DupIncluded::createFolderStructure($file);
     //----------------------------------------------------------
     if (file_put_contents($file, $content)) {
         $chk['message'] = $file . " has been successfully created!!!!!";
     } else {
         $chk['bool'] = false;
         $chk['message'] = $file . " was not saved or did not save properly.";
     }
     //----------------------------------------------------------
     return $chk;
 }