.
*/
include("./include/include.php");
admin_header();
if( !in_array($_SESSION['sess_access'], array("chair", "admin")) ) {
echoln("You are not authorized to see this page.");
}else {
echoln("
Please provide a subject of maximum 64 characters.");
$error = true;
}
$data = "";
switch($_FILES['file']['error']) {
case UPLOAD_ERR_OK: // There is no error, the file uploaded with success.
if( strlen($filename)<3 ) $filename = $_FILES['file']['name'];
if( strlen($filetype)<3 ) $filetype = $_FILES['file']['type'];
if( is_uploaded_file($_FILES['file']['tmp_name']) ) {
if( filesize($_FILES['file']['tmp_name'])>pow(2, 24) ) { // MySQL 'mediumblob' field length max
echoln("
The file you uploaded exceeded the limit of ".get_bytesize(min(pow(2, 24), get_bytes(ini_get("upload_max_filesize")))).".");
$error = true;
}elseif( !($data = file_get_contents($_FILES['file']['tmp_name'])) ) {
echoln("
Uploaded file not found on the system, please try again.");
$error = true;
}
break;
case UPLOAD_ERR_INI_SIZE: // The uploaded file exceeds the upload_max_filesize directive in php.ini.
case UPLOAD_ERR_FORM_SIZE: // The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
echoln("
The file you uploaded exceeded the limit of ".get_bytesize(min(pow(2, 24), get_bytes(ini_get("upload_max_filesize")))).".");
$error = true;
break;
case UPLOAD_ERR_PARTIAL: // The uploaded file was only partially uploaded.
echoln("
The file was only partially uploaded. Please try again.");
$error = true;
case UPLOAD_ERR_NO_FILE: // No file was uploaded.
if( $dlid>0 ) {
// User does not want to replace current file
}else {
echoln("
You did not upload a file.");
$error = true;
}
break;
case UPLOAD_ERR_NO_TMP_DIR: // Missing a temporary folder.
case UPLOAD_ERR_CANT_WRITE: // Failed to write file to disk.
default:
echoln("
An unknown error occurred. Please try again. If this fails, contact the webmaster and report error code ".$_FILES['file']['error']. "while uploading a file.");
$error = true;
break;
}
if( strlen($filename)<3 OR strlen($filename)>64 ) {
echoln("
Please provide a file name of maximum 64 characters.");
$error = true;
}
if( array_key_exists($filetype, $FILETYPETRANS) ) $filetype = $FILETYPETRANS[$filetype]; // Translating to known value
if( strlen($filetype)<3 OR strlen($filetype)>64 ) {
echoln("
Please provide a file type of maximum 64 characters.");
$error = true;
}
echoln("
");
if( !$error ) {
## Save ##
if( $dlid==0 ) {
// New file
$query2 = "INSERT INTO `files` (`info_id`, `subject`, `filename`, `filetype`, `data`) ";
$query2.= "VALUES (".addslashes(get_int("id")).", '".addslashes($subject)."', '".addslashes($filename)."', '".addslashes($filetype)."', '".addslashes($data)."')";
}else {
// Edit file
$query2 = "UPDATE `files` SET `subject`='".addslashes($subject)."', `filename`='".addslashes($filename)."', `filetype`='".addslashes($filetype)."'";
if( strlen($data)>0 ) {
// replace data as well
$query2.= ", `data`='".addslashes($data)."'";
}
$query2.=" WHERE `id`=".$dlid." AND `info_id`=".get_int("id");
}
if( doquery($query2) ) {
echoln("Saved file successfully.
");
}elseif( $dl!="nolist" ) {
## List ##
echoln("Add download
");
$query2 = "SELECT `id`, `subject`, `filename`, `filetype`, LENGTH(`data`) AS `size` FROM `files` WHERE `info_id`=".addslashes(get_int("id"))." ORDER BY `subject`";
if( @mysql_num_rows( $res2=doquery($query2) )>0 ) {
echoln("