Example #1
0
File: io.php Project: LFSF/oras
function CreateServerFolder($folderPath)
{
    $sParent = GetParentFolder($folderPath);
    // Check if the parent exists, or create it.
    if (!file_exists($sParent)) {
        $sErrorMsg = CreateServerFolder($sParent);
        if ($sErrorMsg != '') {
            return $sErrorMsg;
        }
    }
    if (!file_exists($folderPath)) {
        // Turn off all error reporting.
        error_reporting(0);
        // Enable error tracking to catch the error.
        ini_set('track_errors', '1');
        // To create the folder with 0777 permissions, we need to set umask to zero.
        $oldumask = umask(0);
        mkdir($folderPath, 0777);
        umask($oldumask);
        $sErrorMsg = $php_errormsg;
        // Restore the configurations.
        ini_restore('track_errors');
        ini_restore('error_reporting');
        return $sErrorMsg;
    } else {
        return '';
    }
}
Example #2
0
File: io.php Project: apoxa/ckgedit
function CreateServerFolder($folderPath, $lastFolder = null)
{
    global $Config;
    $sParent = GetParentFolder($folderPath);
    // Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms
    while (strpos($folderPath, '//') !== false) {
        $folderPath = str_replace('//', '/', $folderPath);
        $sParent = str_replace('//', '/', $sParent);
    }
    // Check if the parent exists, or create it.
    if (!file_exists($sParent)) {
        //prevents agains infinite loop when we can't create root folder
        if (!is_null($lastFolder) && $lastFolder === $sParent) {
            return "Can't create {$folderPath} directory";
        }
        $sErrorMsg = CreateServerFolder($sParent, $folderPath);
        if ($sErrorMsg != '') {
            return $sErrorMsg;
        }
    }
    if (!file_exists($folderPath)) {
        // Turn off all error reporting.
        error_reporting(0);
        $php_errormsg = '';
        // Enable error tracking to catch the error.
        ini_set('track_errors', '1');
        if (isset($Config['ChmodOnFolderCreate']) && !$Config['ChmodOnFolderCreate']) {
            mkdir($folderPath);
        } else {
            $permissions = 0777;
            if (isset($Config['ChmodOnFolderCreate'])) {
                $permissions = $Config['ChmodOnFolderCreate'];
            }
            // To create the folder with 0777 permissions, we need to set umask to zero.
            $oldumask = umask(0);
            mkdir($folderPath, $permissions);
            umask($oldumask);
        }
        $sErrorMsg = $php_errormsg;
        // Restore the configurations.
        ini_restore('track_errors');
        ini_restore('error_reporting');
        return $sErrorMsg;
    } else {
        return '';
    }
}
Example #3
0
function CreateServerFolder($folderPath, $lastFolder = null)
{
    global $Config;
    $sParent = GetParentFolder($folderPath);
    // Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms
    while (strpos($folderPath, '//') !== false) {
        $folderPath = str_replace('//', '/', $folderPath);
    }
    // Check if the parent exists, or create it.
    if (!empty($sParent) && !file_exists($sParent)) {
        //prevents agains infinite loop when we can't create root folder
        if (!is_null($lastFolder) && $lastFolder === $sParent) {
            return "Can't create {$folderPath} directory";
        }
        $sErrorMsg = CreateServerFolder($sParent, $folderPath);
        if ($sErrorMsg != '') {
            return $sErrorMsg;
        }
    }
    if (!file_exists($folderPath)) {
        // Turn off all error reporting.
        error_reporting(0);
        $php_errormsg = '';
        // Enable error tracking to catch the error.
        ini_set('track_errors', '1');
        if (isset($Config['ChmodOnFolderCreate']) && !$Config['ChmodOnFolderCreate']) {
            mkdir($folderPath);
        } else {
            $permissions = 0777;
            // $permissions = 0770 ;
            if (isset($Config['ChmodOnFolderCreate'])) {
                $permissions = $Config['ChmodOnFolderCreate'];
            }
            // To create the folder with 0777 permissions, we need to set umask to zero.
            //$oldumask = umask(0) ;
            mkdir($folderPath, $permissions);
            //umask( $oldumask ) ;
        }
        // While we are in a course: Registering the newly created folder in the course's database.
        if (api_is_in_course()) {
            global $_course, $_user;
            $repository_path = api_get_path(REL_COURSE_PATH) . api_get_course_path() . '/document/';
            $to_group_id = 0;
            if (api_is_in_group()) {
                global $group_properties;
                $to_group_id = $group_properties['id'];
            }
            $folder_path = preg_replace("/^.*" . TOOL_DOCUMENT . "/", "", $folderPath);
            //
            $folder_path = preg_replace("/\\/\$/", "", $folder_path);
            // should be done in 1 regexp I guess ...
            // $folder_path = substr($folderPath, strpos($folderPath, $repository_path) + strlen($repository_path) - 1);
            $folder_name = explode('/', $folder_path);
            $folder_name = $folder_name[count($folder_name) - 1];
            $doc_id = add_document($_course, $folder_path, 'folder', 0, $folder_name);
            api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], $to_group_id);
        }
        $sErrorMsg = $php_errormsg;
        // Restore the configurations.
        ini_restore('track_errors');
        ini_restore('error_reporting');
        return $sErrorMsg;
    } else {
        return '';
    }
}