Exemplo n.º 1
0
        echo 'Error : ' . $archive->errorInfo(true);
        FileUtility::clr_dir($import_path);
        header('Location: question_db.php?_course_id=' . $_course_id);
        exit;
    }
    error_reporting(TR_ERROR_REPORTING);
}
/* get the course's max_quota */
$coursesDAO = new CoursesDAO();
$q_row = $coursesDAO->get($_course_id);
if ($q_row['max_quota'] != TR_COURSESIZE_UNLIMITED) {
    $zip_size_limit = $MaxCourseSize;
    $totalBytes = FileUtility::dirsize($import_path);
    $total_after = $zip_size_limit - $totalBytes;
    if (is_dir(TR_CONTENT_DIR . $_course_id . '/')) {
        $course_total = FileUtility::dirsize(TR_CONTENT_DIR . $_course_id . '/');
        $total_after -= $course_total;
    }
    if ($total_after < 0) {
        /* remove the content dir, since there's no space for it */
        $errors = array('NO_CONTENT_SPACE', number_format(-1 * ($total_after / TR_KBYTE_SIZE), 2));
        $msg->addError($errors);
        // Clean up import path and inserted course row
        FileUtility::clr_dir($import_path);
        header('Location: index.php?_course_id=' . $_course_id);
        exit;
    }
}
$ims_manifest_xml = @file_get_contents($import_path . 'imsmanifest.xml');
if ($ims_manifest_xml === false) {
    $msg->addError('NO_IMSMANIFEST');
Exemplo n.º 2
0
 /**
  * Calculate the size in Bytes of a directory recursively.
  * @access  public
  * @param   string $dir		the directory to traverse
  * @return  int				the total size in Bytes of the directory
  * @author  Joel Kronenberg
  */
 public static function dirsize($dir)
 {
     if (is_dir($dir)) {
         $dh = @opendir($dir);
     }
     if (!$dh) {
         return -1;
     }
     $size = 0;
     while (($file = readdir($dh)) !== false) {
         if ($file != '.' && $file != '..') {
             $path = $dir . $file;
             if (is_dir($path)) {
                 $size += FileUtility::dirsize($path . '/');
             } elseif (is_file($path)) {
                 $size += filesize($path);
             }
         }
     }
     closedir($dh);
     return $size;
 }
Exemplo n.º 3
0
     $errors = array('FILE_ILLEGAL', $ext);
     $msg->addError($errors);
     FileUtility::handleAjaxUpload(500);
     header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'framed=' . $framed . SEP . 'cp=' . $_GET['cp'] . SEP . 'pid=' . $_GET['pid'] . SEP . 'cid=' . $_GET['cid'] . SEP . 'a_type=' . $_GET['a_type'] . SEP . '_course_id=' . $_course_id);
     exit;
 }
 /* also have to handle the 'application/x-zip-compressed'  case	*/
 if ($_FILES['uploadedfile']['type'] == 'application/x-zip-compressed' || $_FILES['uploadedfile']['type'] == 'application/zip' || $_FILES['uploadedfile']['type'] == 'application/x-zip') {
     $is_zip = true;
 }
 /* anything else should be okay, since we're on *nix.. hopefully */
 $_FILES['uploadedfile']['name'] = str_replace(array(' ', '/', '\\', ':', '*', '?', '"', '<', '>', '|', '\''), '', $_FILES['uploadedfile']['name']);
 /* if the file size is within allowed limits */
 if ($_FILES['uploadedfile']['size'] > 0 && $_FILES['uploadedfile']['size'] <= $my_MaxFileSize) {
     /* if adding the file will not exceed the maximum allowed total */
     $course_total = FileUtility::dirsize($path);
     if ($course_total + $_FILES['uploadedfile']['size'] <= $my_MaxCourseSize || $my_MaxCourseSize == TR_COURSESIZE_UNLIMITED) {
         /* check if this file exists first */
         if (file_exists($path . $_FILES['uploadedfile']['name'])) {
             /* this file already exists, so we want to prompt for override */
             /* save it somewhere else, temporarily first			*/
             /* file_name.time ? */
             $_FILES['uploadedfile']['name'] = substr(time(), -4) . '.' . $_FILES['uploadedfile']['name'];
             $f = array('FILE_EXISTS', substr($_FILES['uploadedfile']['name'], 5), $_FILES['uploadedfile']['name']);
             $msg->addFeedback($f);
         }
         /* copy the file in the directory */
         $result = move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $path . $_FILES['uploadedfile']['name']);
         if (!$result) {
             require TR_INCLUDE_PATH . 'header.inc.php';
             $msg->printErrors('FILE_NOT_SAVED');
    $dir = opendir($current_path);
}
// loop through folder to get files and directory listing
while (false !== ($file = readdir($dir))) {
    // if the name is not a directory
    if ($file == '.' || $file == '..') {
        continue;
    }
    // get some info about the file
    $filedata = stat($current_path . $pathext . $file);
    $path_parts = pathinfo($file);
    $ext = strtolower($path_parts['extension']);
    $is_dir = false;
    // if it is a directory change the file name to a directory link
    if (is_dir($current_path . $pathext . $file)) {
        $size = FileUtility::dirsize($current_path . $pathext . $file . '/');
        $totalBytes += $size;
        $filename = '<a href="' . $_SERVER['PHP_SELF'] . '?pathext=' . urlencode($pathext . $file . '/') . SEP . 'popup=' . $popup . SEP . 'framed=' . $framed . SEP . 'cp=' . $_GET['cp'] . SEP . 'pid=' . $_GET['pid'] . SEP . '_cid=' . $cid . SEP . 'a_type=' . $a_type . SEP . '_course_id=' . $_course_id . '">' . $file . '</a>';
        $fileicon = '&nbsp;';
        $fileicon .= '<img src="images/folder.gif" alt="' . _AT('folder') . ':' . $file . '" height="18" width="20" class="img-size-fm1" />';
        $fileicon .= '&nbsp;';
        if (!$MakeDirOn) {
            $deletelink = '';
        }
        $is_dir = true;
    } else {
        if ($ext == 'zip') {
            $totalBytes += $filedata[7];
            $filename = $file;
            $fileicon = '&nbsp;<img src="images/icon-zip.gif" alt="' . _AT('zip_archive') . ':' . $file . '" height="16" width="16" border="0" class="img-size-fm2" />&nbsp;';
        } else {
Exemplo n.º 5
0
function check_available_size($course_id)
{
    global $coursesDAO, $MaxCourseSize, $import_path, $msg, $oauth_import;
    $q_row = $coursesDAO->get($course_id);
    //$sql	= "SELECT max_quota FROM ".TABLE_PREFIX."courses WHERE course_id=$_SESSION[course_id]";
    //$result = mysql_query($sql, $db);
    //$q_row	= mysql_fetch_assoc($result);
    if ($q_row['max_quota'] == TR_COURSESIZE_UNLIMITED) {
        return;
    } else {
        $zip_size_limit = $MaxCourseSize;
    }
    $totalBytes = FileUtility::dirsize($import_path);
    $total_after = $zip_size_limit - $totalBytes;
    if (is_dir(TR_CONTENT_DIR . $course_id . '/')) {
        $course_total = FileUtility::dirsize(TR_CONTENT_DIR . $course_id . '/');
        $total_after -= $course_total;
    }
    if ($total_after < 0) {
        /* remove the content dir, since there's no space for it */
        $errors = array('NO_CONTENT_SPACE', number_format(-1 * ($total_after / TR_KBYTE_SIZE), 2));
        $msg->addError($errors);
        // Clean up import path and inserted course row
        FileUtility::clr_dir($import_path);
        $coursesDAO->Delete($course_id);
        if (isset($_GET['tile'])) {
            header('Location: ' . $_base_path . 'tools/tile/index.php');
        } else {
            if ($oauth_import) {
                echo "error=" . urlencode('No space for the content.');
            } else {
                header('Location: ' . $_SERVER['HTTP_REFERER']);
            }
        }
        exit;
    }
}