2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2004 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
19 if (!authenticate(AT_PRIV_FILES,AT_PRIV_RETURN)) {
20 authenticate(AT_PRIV_CONTENT);
23 $_SESSION['done'] = 1;
24 $popup = $_REQUEST['popup'];
25 $framed = $_REQUEST['framed'];
27 /* get this courses MaxQuota and MaxFileSize: */
28 $sql = "SELECT max_quota, max_file_size FROM ".TABLE_PREFIX."courses WHERE course_id=$_SESSION[course_id]";
29 $result = mysql_query($sql, $db);
30 $row = mysql_fetch_array($result);
31 $my_MaxCourseSize = $row['max_quota'];
32 $my_MaxFileSize = $row['max_file_size'];
34 if ($my_MaxCourseSize == AT_COURSESIZE_DEFAULT) {
35 $my_MaxCourseSize = $MaxCourseSize;
37 if ($my_MaxFileSize == AT_FILESIZE_DEFAULT) {
38 $my_MaxFileSize = $MaxFileSize;
39 } else if ($my_MaxFileSize == AT_FILESIZE_SYSTEM_MAX) {
40 $my_MaxFileSize = megabytes_to_bytes(substr(ini_get('upload_max_filesize'), 0, -1));
43 $path = AT_CONTENT_DIR . $_SESSION['course_id'].'/'.$_POST['pathext'];
45 if (isset($_POST['submit'])) {
47 if($_FILES['uploadedfile']['name']) {
49 $_FILES['uploadedfile']['name'] = trim($_FILES['uploadedfile']['name']);
50 $_FILES['uploadedfile']['name'] = str_replace(' ', '_', $_FILES['uploadedfile']['name']);
52 $path_parts = pathinfo($_FILES['uploadedfile']['name']);
53 $ext = $path_parts['extension'];
55 /* check if this file extension is allowed: */
56 /* $IllegalExtentions is defined in ./include/config.inc.php */
57 if (in_array($ext, $IllegalExtentions)) {
58 $errors = array('FILE_ILLEGAL', $ext);
59 $msg->addError($errors);
60 header('Location: index.php?pathext='.$_POST['pathext']);
64 /* also have to handle the 'application/x-zip-compressed' case */
65 if ( ($_FILES['uploadedfile']['type'] == 'application/x-zip-compressed')
66 || ($_FILES['uploadedfile']['type'] == 'application/zip')
67 || ($_FILES['uploadedfile']['type'] == 'application/x-zip')){
72 /* anything else should be okay, since we're on *nix.. hopefully */
73 $_FILES['uploadedfile']['name'] = str_replace(array(' ', '/', '\\', ':', '*', '?', '"', '<', '>', '|', '\''), '', $_FILES['uploadedfile']['name']);
76 /* if the file size is within allowed limits */
77 if( ($_FILES['uploadedfile']['size'] > 0) && ($_FILES['uploadedfile']['size'] <= $my_MaxFileSize) ) {
79 /* if adding the file will not exceed the maximum allowed total */
80 $course_total = dirsize($path);
82 if ((($course_total + $_FILES['uploadedfile']['size']) <= ($my_MaxCourseSize + $MaxCourseFloat)) || ($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED)) {
84 /* check if this file exists first */
85 if (file_exists($path.$_FILES['uploadedfile']['name'])) {
86 /* this file already exists, so we want to prompt for override */
88 /* save it somewhere else, temporarily first */
89 /* file_name.time ? */
90 $_FILES['uploadedfile']['name'] = substr(time(), -4).'.'.$_FILES['uploadedfile']['name'];
92 $f = array('FILE_EXISTS',
93 substr($_FILES['uploadedfile']['name'], 5),
94 $_FILES['uploadedfile']['name'],
98 $msg->addFeedback($f);
101 /* copy the file in the directory */
102 $result = move_uploaded_file( $_FILES['uploadedfile']['tmp_name'], $path.$_FILES['uploadedfile']['name'] );
105 require(AT_INCLUDE_PATH.'header.inc.php');
106 $msg->printErrors('FILE_NOT_SAVED');
107 echo '<a href="tools/filemanager/index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup'] . '">' . _AT('back') . '</a>';
108 require(AT_INCLUDE_PATH.'footer.inc.php');
112 $f = array('FILE_UPLOADED_ZIP',
113 urlencode($_POST['pathext']),
114 urlencode($_FILES['uploadedfile']['name']),
117 $msg->addFeedback($f);
119 header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup']);
123 $msg->addFeedback('FILE_UPLOADED');
125 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'popup='.$_GET['popup']);
129 $msg->addError(array('MAX_STORAGE_EXCEEDED', get_human_size($my_MaxCourseSize)));
130 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'popup='.$_GET['popup']);
134 $msg->addError(array('FILE_TOO_BIG', get_human_size($my_MaxFileSize)));
135 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'popup='.$_GET['popup']);
139 $msg->addError('FILE_NOT_SELECTED');
140 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'popup='.$_GET['popup']);