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
function CreateFolder($resourceType, $currentFolder)
{
    $sErrorNumber = '0';
    $sErrorMsg = '';
    if (isset($_GET['NewFolderName'])) {
        $sNewFolderName = $_GET['NewFolderName'];
        // Map the virtual path to the local server path of the current folder.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder);
        if (is_writable($sServerDir)) {
            $sServerDir .= $sNewFolderName;
            $sErrorMsg = CreateServerFolder($sServerDir);
            switch ($sErrorMsg) {
                case '':
                    $sErrorNumber = '0';
                    break;
                case 'Invalid argument':
                case 'No such file or directory':
                    $sErrorNumber = '102';
                    // Path too long.
                    break;
                default:
                    $sErrorNumber = '110';
                    break;
            }
        } else {
            $sErrorNumber = '103';
        }
    } else {
        $sErrorNumber = '102';
    }
    // Create the "Error" node.
    echo '<Error number="' . $sErrorNumber . '" originalDescription="' . ConvertToXmlAttribute($sErrorMsg) . '" />';
}
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 ( !file_exists( $sParent ) )
    if (!empty($sParent) && !file_exists($sParent)) {
        //prevents agains infinite loop when we can't create root folder
        if (!is_null($lastFolder) && $lastFolder === $sParent) {
            return "Не могу создать директорию " . $folderPath;
        }
        $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 #4
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');
        $oldumask = umask(0);
        mkdir($folderPath);
        umask($oldumask);
        $sErrorMsg = $php_errormsg;
        // Restore the configurations.
        ini_restore('track_errors');
        ini_restore('error_reporting');
        return $sErrorMsg;
    } else {
        return '';
    }
}
Example #5
0
function CreateFolder($resourceType, $currentFolder)
{
    if (!isset($_GET)) {
        global $_GET;
    }
    $sErrorNumber = '0';
    $sErrorMsg = '';
    if (isset($_GET['NewFolderName'])) {
        $sNewFolderName = $_GET['NewFolderName'];
        $sNewFolderName = SanitizeFolderName($sNewFolderName);
        if (strpos($sNewFolderName, '..') !== FALSE) {
            $sErrorNumber = '102';
        } else {
            // Map the virtual path to the local server path of the current folder.
            $sServerDir = ServerMapFolder($resourceType, $currentFolder, 'CreateFolder');
            if (is_writable($sServerDir)) {
                $sServerDir .= $sNewFolderName;
                $sErrorMsg = CreateServerFolder($sServerDir);
                switch ($sErrorMsg) {
                    case '':
                        $sErrorNumber = '0';
                        break;
                    case 'Invalid argument':
                    case 'No such file or directory':
                        $sErrorNumber = '102';
                        // Path too long.
                        break;
                    default:
                        $sErrorNumber = '110';
                        break;
                }
            } else {
                $sErrorNumber = '103';
            }
        }
    } else {
        $sErrorNumber = '102';
    }
    // Create the "Error" node.
    echo '<Error number="' . $sErrorNumber . '" />';
}
Example #6
0
function CreateFolder($resourceType, $currentFolder)
{
    global $_FolderClass;
    global $Config;
    if (!isset($_GET)) {
        global $_GET;
    }
    $sErrorNumber = '0';
    $sErrorMsg = '';
    if (!has_permission($currentFolder, $resourceType) || $_FolderClass < 8) {
        if (!has_open_access()) {
            $sErrorNumber = 103;
            echo '<Error number="' . $sErrorNumber . '" />';
            return;
        }
    }
    if (isset($_GET['NewFolderName'])) {
        $sess_id = session_id();
        if (!isset($sess_id) || $sess_id != $_COOKIE['FCK_NmSp_acl']) {
            session_id($_COOKIE['FCK_NmSp_acl']);
            session_start();
        }
        global $Dwfck_conf_values;
        global $dwfck_conf;
        $dwfck_conf = $_SESSION['dwfck_conf'];
        if (empty($dwfck_conf)) {
            $dwfck_conf['deaccent'] = isset($Dwfck_conf_values['deaccent']) ? $Dwfck_conf_values['deaccent'] : 1;
            $dwfck_conf['useslash'] = isset($Dwfck_conf_values['useslash']) ? $Dwfck_conf_values['useslash'] : 0;
            $dwfck_conf['sepchar'] = isset($Dwfck_conf_values['sepchar']) ? $Dwfck_conf_values['sepchar'] : '_';
        }
        $sNewFolderName = $_GET['NewFolderName'];
        $sNewFolderName = str_replace(' ', $dwfck_conf['sepchar'], $sNewFolderName);
        $sNewFolderName = Dwfck_sanitize($sNewFolderName);
        if (strpos($sNewFolderName, '..') !== FALSE) {
            $sErrorNumber = '102';
        } else {
            // Map the virtual path to the local server path of the current folder.
            $sServerDir = ServerMapFolder($resourceType, $currentFolder, 'CreateFolder');
            if ($Dwfck_conf_values['fnencode'] == 'url' || $Config['osWindows'] && !isset($Dwfck_conf_values['fnencode'])) {
                $sServerDir = encode_dir($sServerDir);
            }
            if ($Config['osWindows']) {
                $sServerDir = normalizeWIN($sServerDir);
            }
            if (is_writable($sServerDir)) {
                $sServerDir .= $sNewFolderName;
                $sErrorMsg = CreateServerFolder($sServerDir);
                switch ($sErrorMsg) {
                    case '':
                        $sErrorNumber = '0';
                        break;
                    case 'Invalid argument':
                    case 'No such file or directory':
                        $sErrorNumber = '102';
                        // Path too long.
                        break;
                    default:
                        $sErrorNumber = '110';
                        break;
                }
            } else {
                $sErrorNumber = '103';
            }
        }
    } else {
        $sErrorNumber = '102';
    }
    // Create the "Error" node.
    echo '<Error number="' . $sErrorNumber . '" />';
}
Example #7
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 '';
    }
}
Example #8
0
 // Strip the temp .part suffix off
 @rename("{$filePath}.part", $filePath);
 // Time to move the temp file to the right folder
 $_FILES['NewFile']['name'] = $fileName;
 $_FILES['NewFile']['size'] = @filesize($filePath);
 $_FILES['NewFile']['tmp_name'] = $filePath;
 $_FILES['NewFile']['error'] = 0;
 // get our existing uploader into action
 define('K_GALLERY_UPLOAD', 1);
 require_once K_COUCH_DIR . 'includes/fileuploader/connector.php';
 $_GET['Type'] = 'Image';
 // create destination folder if required
 $fn = trim(implode('/', array_map(array($FUNCS, 'get_clean_url'), explode('/', $fn))), '/');
 $fpath = $Config['UserFilesAbsolutePath'] . 'image/';
 $fpath .= $fn ? $fn . '/' : '';
 $res = CreateServerFolder($fpath);
 if ($res) {
     die($res);
 }
 // move the file
 global $_K_IMAGE;
 // will contain either full url of the uploaded image or error
 $_GET['Command'] = 'FileUpload';
 $_GET['CurrentFolder'] = $fn;
 DoResponse();
 // success?
 if ($FUNCS->is_error($_K_IMAGE)) {
     die($_K_IMAGE->err_msg);
 }
 // Move on to create a cloned page using the uploaded image
 $path_parts = $FUNCS->pathinfo($fileName);
Example #9
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // hack for XOOPS CHINA by ezsky < *****@*****.** >
        $name_pattern = "";
        if (!empty($Config['UserFilesNamePattern'])) {
            $patterns = explode("|", $Config['UserFilesNamePattern']);
            $delimiter = "";
            foreach ($patterns as $pattern) {
                switch ($pattern) {
                    case "date":
                        $name_pattern .= $delimiter . date("YmdHis");
                        break;
                    case "time":
                        $name_pattern .= $delimiter . strval(time());
                        break;
                    case "uid":
                        $name_pattern .= $delimiter . (is_object($GLOBALS["xoopsUser"]) ? str_pad($GLOBALS["xoopsUser"]->getVar("uid"), 10, "0", STR_PAD_LEFT) : "0");
                        break;
                }
                $delimiter = "-";
            }
        }
        if (!empty($name_pattern)) {
            $sFileName = $name_pattern . "." . $sExtension;
        }
        if (!empty($Config['UserFilesPathPattern'])) {
            $sServerDir .= date($Config['UserFilesPathPattern']) . '/';
            CreateServerFolder($sServerDir);
            if (is_dir($sServerDir)) {
                $currentFolder .= date($Config['UserFilesPathPattern']) . '/';
            }
        }
        // end hack
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}