// All rights reserved.
This script is part of PHPWCMS. The PHPWCMS web content management system is
free software; you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
A copy is found in the textfile GPL.txt and important notices to the license
from the author is found in LICENSE.txt distributed with these scripts.
This script is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------
// initialize Mootools for autocomplete
initMootoolsAutocompleter();
// Upload new file
$file_aktiv = 1;
$file_public = 0;
$file_shortinfo = '';
$file_longinfo = '';
$file_pid = empty($_GET["upload"]) ? 0 : intval($_GET["upload"]);
$file_copyright = '';
$file_tags = '';
$file_granted = 0;
$file_gallerydownload = 0;
$file_sort = 0;
//Auswerten des Formulars
if(isset($_POST["file_aktion"]) && intval($_POST["file_aktion"]) == 1) {
if(!ini_get('safe_mode') && function_exists('set_time_limit')) set_time_limit(0);
$file_pid = intval($_POST["file_pid"]);
$file_aktiv = empty($_POST["file_aktiv"]) ? 0 : 1;
$file_public = empty($_POST["file_public"]) ? 0 : 1;
$file_shortinfo = clean_slweg($_POST["file_shortinfo"]);
$file_longinfo = slweg(trim($_POST["file_longinfo"]));
$file_copyright = clean_slweg($_POST["file_copyright"]);
$file_tags = trim( clean_slweg($_POST["file_tags"]), ',' );
$file_granted = empty($_POST["file_granted"]) ? 0 : 1;
$file_gallerydownload = empty($_POST["file_gallerydownload"]) ? 0 : 1;
$file_keys = '';
$file_sort = intval($_POST["file_sort"]);
$file_keywords = empty($_POST["file_keywords"]) ? array() : $_POST["file_keywords"];
if(count($file_keywords)) {
foreach($file_keywords as $key => $value) {
unset($file_keywords[$key]);
$key = intval($key);
if($value != "0_1") {
$file_keys .= (($file_keys) ? ":" : "").$key."_".intval($value);
$file_keywords[$key] = intval($value);
} else {
$file_error["keywords"][$key] = 1;
}
}
}
//starts upload of file
if(!is_uploaded_file($_FILES["file"]["tmp_name"])) {
$file_error["file"] = $BL['be_fprivup_err1'];
} else {
if($_FILES["file"]["size"] > $phpwcms["file_maxsize"]) {
$file_error["file"] = $BL['be_fprivup_err2']." ".number_format($phpwcms["file_maxsize"] / 1024, 2, ',', '.')." kB";
}
}
//Create new file in database and give hashed
if(!isset($file_error)) {
$fileExt = check_image_extension($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);
$fileExt = $fileExt === false ? which_ext($_FILES["file"]["name"]) : $fileExt;
$fileName = clearfilename($_FILES["file"]["name"]);
$fileHash = md5( $fileName . microtime() );
$fileType = is_mimetype_format($_FILES["file"]["type"]) ? $_FILES["file"]["type"] : get_mimetype_by_extension($fileExt);
$sql = "INSERT INTO ".DB_PREPEND."phpwcms_file (".
"f_pid, f_uid, f_kid, f_aktiv, f_public, f_name, f_created, f_size, f_type, f_ext, ".
"f_shortinfo, f_longinfo, f_keywords, f_hash, f_copyright, f_tags, f_granted, f_gallerystatus, f_sort) VALUES (".
$file_pid.", ".intval($_SESSION["wcs_user_id"]).", 1, ".$file_aktiv.", ".$file_public.", '".
$fileName."', '".time()."', '".intval($_FILES["file"]["size"])."', '".
aporeplace($fileType)."', '".$fileExt."', '".aporeplace($file_shortinfo)."', '".
aporeplace($file_longinfo)."', '".aporeplace($file_keys)."', '".aporeplace($fileHash)."', '".
aporeplace($file_copyright)."', '".aporeplace($file_tags)."', ".$file_granted.", ".
$file_gallerydownload.", ".$file_sort.")";
if($result = mysql_query($sql, $db) or die("error while insert file information")) {
$new_fileId = mysql_insert_id($db); //Festlegen der aktuellen File-ID
$wcs_newfilename = ($fileExt) ? $fileHash.'.'.$fileExt : $fileHash;
// changed for using hashed file names
$useruploadpath = PHPWCMS_ROOT.$phpwcms["file_path"];
$usernewfile = $useruploadpath.$wcs_newfilename;
if ($dir = @opendir($useruploadpath)) {
if(!@move_uploaded_file($_FILES["file"]["tmp_name"], $usernewfile)) {
$file_error["upload"] = $BL['be_fprivup_err3'].' (1)';
}
} else {
$oldumask = umask(0);
if(@mkdir($useruploadpath, 0777)) {;
if(!@move_uploaded_file($_FILES["file"]["tmp_name"], $usernewfile)) {
$file_error["upload"] = $BL['be_fprivup_err3'].' (2)';
}
} else {
$file_error["upload"] = $BL['be_fprivup_err4'];
}
umask($oldumask);
}
if(file_exists($usernewfile)) {
@chmod($usernewfile, 0666);
}
if(!isset($file_error["upload"])) {
// store tags
_dbSaveCategories($file_tags, 'file', $new_fileId, ',');
//after successful upload go back to clear post (form) var
headerRedirect(PHPWCMS_URL."phpwcms.php?do=files&f=0&uploaded=1");
} else {
echo $file_error["upload"]."
";
$file_error["upload"] = str_replace('{VAL}', $phpwcms["admin_email"], $BL['be_fprivup_err6']);
mysql_query("DELETE FROM ".DB_PREPEND."phpwcms_file WHERE f_id=".$new_fileId." AND f_uid=".$_SESSION["wcs_user_id"].";", $db);
}
}
}
if(!ini_get('safe_mode') && function_exists('set_time_limit')) set_time_limit(30);
}
//Ende Auswerten Formular
?>