示例#1
0
文件: user.lib.php 项目: rhertzog/lcs
/**
 * Handle user's profile picture modification
 * (based on $_REQUEST['delPicture'] and $_FILE['picture'].
 *
 * @return  $feedback array (yes, it is kinda ugly)
 */
function user_handle_profile_picture($userData)
{
    $feedback = array('success' => false, 'messages' => array(), 'pictureName' => '');
    // Handle user picture
    if (!empty($_REQUEST['delPicture'])) {
        $picturePath = user_get_picture_path($userData);
        if ($picturePath) {
            claro_delete_file($picturePath);
            $feedback['success'] = true;
            $feedback['messages'][] = get_lang("User picture deleted");
        } else {
            $feedback['messages'][] = get_lang("Cannot delete user picture");
        }
    }
    if (isset($_FILES['picture']['name']) && $_FILES['picture']['size'] > 0) {
        $fileName = $_FILES['picture']['name'];
        $fileTmpName = $_FILES['picture']['tmp_name'];
        if (is_uploaded_file($fileTmpName)) {
            // Is it an picture ?
            if (is_image($fileName)) {
                // Does it meet the platform's requirements
                list($width, $height, $type, $attr) = getimagesize($fileTmpName);
                if ($width > 0 && $width <= get_conf('maxUserPictureWidth', 150) && $height > 0 && $height <= get_conf('maxUserPictureHeight', 200) && $_FILES['picture']['size'] <= get_conf('maxUserPictureSize', 100 * 1024)) {
                    $uploadDir = user_get_private_folder_path($userData['user_id']);
                    if (!file_exists($uploadDir)) {
                        claro_mkdir($uploadDir, CLARO_FILE_PERMISSIONS, true);
                    }
                    // User's picture successfully treated
                    if (false !== ($pictureName = treat_uploaded_file($_FILES['picture'], $uploadDir, '', 1000000000000.0))) {
                        $feedback['success'] = true;
                        $feedback['messages'][] = get_lang("User picture added");
                        $feedback['pictureName'] = $pictureName;
                    } else {
                        $feedback['messages'][] = get_lang("Cannot upload file");
                    }
                } else {
                    $feedback['messages'][] = get_lang("Image is too big : max size %width%x%height%, %size% bytes", array('%width%' => get_conf('maxUserPictureWidth', 150), '%height%' => get_conf('maxUserPictureHeight', 200), '%size%' => get_conf('maxUserPictureHeight', 100 * 1024)));
                }
            } else {
                $feedback['messages'][] = get_lang("Invalid file format, use gif, jpg or png");
            }
        } else {
            $feedback['messages'][] = get_lang('Upload failed');
        }
    }
    return $feedback;
}
示例#2
0
/**
 * @return the path of the temporary directory where the exercise was uploaded and unzipped
 */
function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadDir)
{
    //Check if the file is valid (not to big and exists)
    if (!isset($_FILES['uploadedExercise']) || !is_uploaded_file($_FILES['uploadedExercise']['tmp_name'])) {
        // upload failed
        return false;
    }
    //1- Unzip folder in a new repository in claroline/module
    //include_once realpath(dirname(__FILE__) . '/../../inc/lib/pclzip/') . '/pclzip.lib.php';
    require_once get_path('incRepositorySys') . '/lib/thirdparty/pclzip/pclzip.lib.php';
    if (preg_match('/.zip$/i', $_FILES['uploadedExercise']['name']) && treat_uploaded_file($_FILES['uploadedExercise'], $baseWorkDir, $uploadDir, get_conf('maxFilledSpaceForExercise', 10000000), 'unzip', true)) {
        if (!function_exists('gzopen')) {
            claro_delete_file($uploadDir);
            return false;
        }
        // upload successfull
        return true;
    } else {
        claro_delete_file($uploadDir);
        return false;
    }
}
示例#3
0
文件: document.php 项目: rhertzog/lcs
 if ('exUpload' == $cmd) {
     if (!isset($_FILES['userFile'])) {
         $dialogBox->error(get_lang('No file uploaded'));
     } else {
         if (isset($_REQUEST['uncompress']) && $_REQUEST['uncompress'] == 1 && $is_allowedToUnzip && preg_match('/.zip$/i', $_FILES['userFile']['name'])) {
             $unzip = 'unzip';
         } else {
             $unzip = '';
         }
         if (isset($_REQUEST['comment']) && trim($_REQUEST['comment']) != '') {
             $comment = trim($_REQUEST['comment']);
         } else {
             $comment = '';
         }
         $cwd = secure_file_path($cwd);
         $uploadedFileName = treat_uploaded_file($_FILES['userFile'], $baseWorkDir, $cwd, $maxFilledSpace, $unzip);
         $uploadedFileNameList = array();
         if ($uploadedFileName !== false) {
             if (isset($_REQUEST['uncompress']) && $_REQUEST['uncompress'] == 1 && $unzip == 'unzip') {
                 $dialogBox->success(get_lang('Zip file uploaded and uncompressed'));
                 foreach ($uploadedFileName as $uploadedFile) {
                     $uploadedFileNameList[] = $cwd . '/' . $uploadedFile['stored_filename'];
                 }
             } else {
                 $dialogBox->success(get_lang('The upload is finished'));
                 $uploadedFileNameList[] = $cwd . '/' . $uploadedFileName;
             }
             if (!empty($comment)) {
                 $cur_dir = $cwd;
                 // add comment to each file
                 foreach ($uploadedFileNameList as $fileName) {
示例#4
0
         $dialogBox->error(get_lang("Cannot delete user picture"));
     }
 }
 // Handle user picture
 if (isset($_FILES['picture']['name']) && $_FILES['picture']['size'] > 0) {
     $fileName = $_FILES['picture']['name'];
     $fileTmpName = $_FILES['picture']['tmp_name'];
     if (is_uploaded_file($fileTmpName)) {
         if (is_image($fileName)) {
             list($width, $height, $type, $attr) = getimagesize($fileTmpName);
             if ($width > 0 && $width <= get_conf('maxUserPictureWidth', 150) && $height > 0 && $height <= get_conf('maxUserPictureHeight', 200) && $_FILES['picture']['size'] <= get_conf('maxUserPictureSize', 100 * 1024)) {
                 $uploadDir = user_get_private_folder_path($user_data['user_id']);
                 if (!file_exists($uploadDir)) {
                     claro_mkdir($uploadDir, CLARO_FILE_PERMISSIONS, true);
                 }
                 if (false !== ($pictureName = treat_uploaded_file($_FILES['picture'], $uploadDir, '', 1000000000000.0))) {
                     // Update Database
                     $user_data['picture'] = $pictureName;
                     $dialogBox->success(get_lang("User picture added"));
                 } else {
                     // Handle Error
                     $dialogBox->error(get_lang("Cannot upload file"));
                 }
             } else {
                 // Handle error
                 $dialogBox->error(get_lang("Image is too big : max size %width%x%height%, %size% bytes", array('%width%' => get_conf('maxUserPictureWidth', 150), '%height%' => get_conf('maxUserPictureHeight', 200), '%size%' => get_conf('maxUserPictureHeight', 100 * 1024))));
             }
         } else {
             // Handle error
             $dialBox->error(get_lang("Invalid file format, use gif, jpg or png"));
         }
示例#5
0
/**
 * Unzip a module package archive and get the path of the unzipped files
 * @todo split this function and use unzip_package()
 * @todo remove the need of the Backlog and use Exceptions instead
 * @return string
 */
function get_and_unzip_uploaded_package()
{
    $backlog_message = array();
    //Check if the file is valid (not to big and exists)
    if (!isset($_FILES['uploadedModule']) || !is_uploaded_file($_FILES['uploadedModule']['tmp_name'])) {
        $backlog_message[] = get_lang('Upload failed');
    }
    require_once dirname(__FILE__) . '/../thirdparty/pclzip/pclzip.lib.php';
    if (!function_exists('gzopen')) {
        $backlog_message[] = get_lang('Error : no zlib extension found');
        return claro_failure::set_failure($backlog_message);
    }
    //unzip files
    // $moduleRepositorySys is the place where go the installed module
    // $uploadDirFullPath is a temporary name of the dir in $moduleRepositorySys the module is unpack
    // $uploadDirFullPath would be renamed to $modulePath when install is done.
    $moduleRepositorySys = get_path('rootSys') . 'module/';
    //create temp dir for upload
    claro_mkdir($moduleRepositorySys, CLARO_FILE_PERMISSIONS, true);
    $uploadDirFullPath = claro_mkdir_tmp($moduleRepositorySys);
    $uploadDir = str_replace(realpath($moduleRepositorySys), '', realpath($uploadDirFullPath));
    $modulePath = realpath($moduleRepositorySys . $uploadDir . '/');
    //1- Unzip folder in a new repository in claroline/module
    // treat_uploaded_file : Executes all the necessary operation to upload the file in the document tool
    // TODO this function would be splited.
    if (preg_match('/.zip$/i', $_FILES['uploadedModule']['name']) && treat_uploaded_file($_FILES['uploadedModule'], $moduleRepositorySys, $uploadDir, get_conf('maxFilledSpaceForModule', 20000000), 'unzip', true)) {
        $backlog_message[] = get_lang('Files dezipped sucessfully in %path', array('%path' => $modulePath));
    } else {
        $backlog_message[] = get_lang('Impossible to unzip file');
        claro_delete_file($modulePath);
        return claro_failure::set_failure($backlog_message);
    }
    return $modulePath;
}