[ Index ] |
PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved. 6 7 This script is part of PHPWCMS. The PHPWCMS web content management system is 8 free software; you can redistribute it and/or modify it under the terms of 9 the GNU General Public License as published by the Free Software Foundation; 10 either version 2 of the License, or (at your option) any later version. 11 12 The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html 13 A copy is found in the textfile GPL.txt and important notices to the license 14 from the author is found in LICENSE.txt distributed with these scripts. 15 16 This script is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 18 PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 20 This copyright notice MUST APPEAR in all copies of the script! 21 *************************************************************************************/ 22 23 // session_name('hashID'); 24 session_start(); 25 $phpwcms = array(); 26 27 require_once ('../../config/phpwcms/conf.inc.php'); 28 require_once ('../inc_lib/default.inc.php'); 29 require_once (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php'); 30 31 require_once (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php'); 32 checkLogin(); 33 require_once (PHPWCMS_ROOT.'/include/inc_lib/backend.functions.inc.php'); 34 35 $ref = $_SESSION['REFERER_URL']; 36 $ftp["error"] = 0; 37 38 $ftp["mark"] = isset($_POST["ftp_mark"]) ? $_POST["ftp_mark"] : false; 39 $ftp["file"] = isset($_POST["ftp_file"]) ? $_POST["ftp_file"] : false; 40 $ftp["filename"] = isset($_POST["ftp_filename"]) ? $_POST["ftp_filename"] : false; 41 42 if(is_array($ftp["mark"]) && count($ftp["mark"])) { 43 foreach($ftp["mark"] as $key => $value) { 44 if(intval($ftp["mark"][$key])) { 45 $ftp["file"][$key] = base64_decode($ftp["file"][$key]); 46 $ftp["filename"][$key] = clean_slweg($ftp["filename"][$key]); 47 } else { 48 unset($ftp["mark"][$key], $ftp["file"][$key], $ftp["filename"][$key]); 49 } 50 } 51 if(!count($ftp["mark"])) $ftp["error"] = 1; 52 } else { 53 $ftp["error"] = 1; 54 } 55 56 ?> 57 <html> 58 <head><title>phpwcms: creating thumbnail</title> 59 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo PHPWCMS_CHARSET ?>"> 60 <meta http-equiv="Expires" content="0"> 61 <meta http-equiv="Pragma" content="no-cache"> 62 <meta http-equiv="cache-control" content="no-cache"> 63 <link href="../inc_css/phpwcms.css" rel="stylesheet" type="text/css"> 64 <style type="text/css"> 65 <!-- 66 body { background-color: #EBF2F4; } 67 --> 68 </style> 69 </head> 70 <body bgcolor="#EBF2F4" text="#000000" link="#000000" vlink="#000000" alink="#000000" leftmargin="15" topmargin="15" marginwidth="15" marginheight="15"> 71 <?php 72 if(!$ftp["error"]) { 73 74 $ftp["dir"] = intval($_POST["file_dir"]); 75 $ftp["short_info"] = clean_slweg($_POST["file_shortinfo"]); 76 77 $ftp["aktiv"] = empty($_POST["file_aktiv"]) ? 0 : 1; 78 $ftp["public"] = empty($_POST["file_public"]) ? 0 : 1; 79 $ftp["replace"] = empty($_POST["file_replace"]) ? 0 : 1; 80 $ftp["long_info"] = clean_slweg($_POST["file_longinfo"]); 81 $ftp["copyright"] = clean_slweg($_POST["file_copyright"]); 82 $ftp["tags"] = trim( trim( clean_slweg($_POST["file_tags"]), ',') ); 83 84 $ftp["keywords"] = isset($_POST["file_keywords"]) ? $_POST["file_keywords"] : array(); 85 $ftp["keys"] = ""; 86 if(is_array($ftp["keywords"]) && count($ftp["keywords"])) { 87 foreach($ftp["keywords"] as $key => $value) { 88 unset($ftp["keywords"][$key]); 89 $key = intval($key); 90 if($value != "0_1") { 91 $ftp["keys"] .= (($ftp["keys"]) ? ":" : "").$key."_".intval($value); 92 $ftp["keywords"][$key] = intval($value); 93 } else { 94 $file_error["keywords"][$key] = 1; 95 } 96 } 97 } 98 99 100 ?><p><img src="../../img/symbole/rotation.gif" alt="" width="15" height="15"><strong class="title"> selected files uploaded via ftp will be taken over!</strong></p><?php 101 102 echo "<p class=\"v10\">"; 103 flush(); 104 105 foreach($ftp["mark"] as $key => $value) { 106 if(!ini_get('safe_mode') && function_exists('set_time_limit')) set_time_limit(60); 107 108 $file = $ftp["file"][$key]; 109 $file_path = PHPWCMS_ROOT.$phpwcms["ftp_path"].$file; 110 if(is_file($file_path)) { 111 112 $file_type = ''; 113 $file_error["upload"] = 0; 114 $file_size = filesize($file_path); 115 116 $file_ext = check_image_extension($file_path); 117 $file_ext = (false === $file_ext) ? which_ext($file) : $file_ext; 118 119 $file_name = $ftp["filename"][$key]; 120 $file_hash = md5( $file_name . microtime() ); 121 122 123 if(trim($file_type) == '') { 124 125 //check file_type 126 if(is_mimetype_by_extension($file_ext)) { 127 $file_type = get_mimetype_by_extension($file_ext); 128 } else { 129 $file_check = getimagesize($file_path); 130 if(version_compare("4.3.0", phpversion(), ">=") && $file_check) { 131 $file_type = image_type_to_mime_type($file_check[2]); 132 } 133 if(!is_mimetype_format($file_type)) { 134 $file_type = get_mimetype_by_extension($file_ext); 135 } 136 } 137 138 } 139 140 $sql = "INSERT INTO ".DB_PREPEND."phpwcms_file (". 141 "f_pid, f_uid, f_kid, f_aktiv, f_public, f_name, f_created, f_size, f_type, f_ext, ". 142 "f_shortinfo, f_longinfo, f_keywords, f_hash, f_copyright, f_tags) VALUES (". 143 $ftp["dir"].", ".intval($_SESSION["wcs_user_id"]).", 1, ".$ftp["aktiv"].", ".$ftp["public"].", '". 144 aporeplace($file_name)."', '".time()."', '".$file_size."', '".aporeplace($file_type)."', '". 145 aporeplace($file_ext)."', '".aporeplace($ftp["short_info"])."', '". 146 aporeplace($ftp["long_info"])."', '".$ftp["keys"]."', '".$file_hash."', '". 147 aporeplace($ftp["copyright"])."', '".aporeplace($ftp["tags"])."')"; 148 149 if($result = mysql_query($sql, $db) or die("error while insert file information")) { 150 $new_fileId = mysql_insert_id($db); //Festlegen der aktuellen File-ID 151 152 $_file_extension = ($file_ext) ? '.'.$file_ext : ''; 153 $wcs_newfilename = $file_hash . $_file_extension; 154 155 // changed for using hashed file names 156 $userftppath = PHPWCMS_ROOT.$phpwcms["ftp_path"]; 157 $useruploadpath = PHPWCMS_ROOT.$phpwcms["file_path"]; 158 $usernewfile = $useruploadpath.$wcs_newfilename; 159 160 161 $oldumask = umask(0); 162 163 if ($dir = @opendir($useruploadpath)) { 164 if(@copy($userftppath.$file, $usernewfile)) { 165 166 @unlink($userftppath.$file); 167 168 // store tags 169 _dbSaveCategories($ftp["tags"], 'file', $new_fileId, ','); 170 171 } else { 172 $file_error["upload"] = "Error while writing file to storage (1)."; 173 } 174 } 175 } 176 177 if(empty($file_error["upload"])) { 178 179 // now try to find 1st file having same named and replace it if related mark is set 180 if($ftp["replace"]) { 181 182 $rsql = "SELECT * FROM ".DB_PREPEND."phpwcms_file WHERE "; 183 $rsql .= "f_name='".aporeplace($file_name)."' AND f_kid=1 "; 184 $rsql .= "AND f_pid=".$ftp["dir"]." AND f_trash=0 AND f_id != ".$new_fileId." LIMIT 1"; 185 if($rresult = mysql_query($rsql, $db)) { 186 187 if($rrow = mysql_fetch_assoc($rresult)) { 188 189 $oldFileID = $rrow['f_id']; 190 $oldFileHash = $rrow['f_hash']; 191 $oldFileNewHash = md5( $file_name . microtime() . time() ); 192 193 // now update new file by old file information of same named 194 $nsql = "UPDATE ".DB_PREPEND."phpwcms_file SET "; 195 $nsql .= "f_refid=".$oldFileID.", f_trash=5, f_size=".$rrow['f_size'].', '; 196 $nsql .= "f_type='".$rrow['f_type']."', f_changed=".now().', '; 197 $nsql .= "f_hash='".aporeplace($oldFileNewHash)."' WHERE f_id=".$new_fileId; 198 199 if(mysql_query($nsql, $db)) { 200 201 // yepp both files are updated in db 202 // now change hash of file storage files 203 rename($useruploadpath.$oldFileHash.$_file_extension, $useruploadpath.$oldFileNewHash.$_file_extension); 204 rename($usernewfile, $useruploadpath.$oldFileHash.$_file_extension); 205 206 // update file size of old file with new filesize 207 _dbUpdate('phpwcms_file', array('f_type'=>$file_type, 'f_size'=>$file_size, 'f_changed'=>now()), 'f_id='.$oldFileID); 208 209 //now try to delete all temp images if available 210 $isql = "SELECT imgcache_imgname FROM ".DB_PREPEND."phpwcms_imgcache WHERE imgcache_hash='".aporeplace($oldFileHash)."'"; 211 if($iresult = mysql_query($isql, $db)) { 212 $cImagePath = PHPWCMS_ROOT . '/' . PHPWCMS_IMAGES; 213 while($irow = mysql_fetch_row($iresult)) { 214 if(file_exists($cImagePath.$irow[0])) { 215 @unlink($cImagePath.$irow[0]); 216 } 217 } 218 } 219 } 220 } 221 mysql_free_result($rresult); 222 223 } 224 225 226 } 227 228 flush(); 229 echo $file." [OK!]<br />"; 230 } else { 231 echo $file." (".$file_error["upload"].")<br />"; 232 mysql_query("DELETE FROM ".DB_PREPEND."phpwcms_file WHERE f_id=".$new_fileId." AND f_uid=".$_SESSION["wcs_user_id"], $db); 233 } 234 235 } else { 236 echo $file." not exists<br />"; 237 } 238 flush(); 239 } 240 echo "</p>\n"; 241 } 242 243 if(empty($file_error["upload"]) && empty($ftp["error"])) { 244 echo "<p class=\"title\"><strong>every selected file was taken over</strong></p>\n"; 245 echo "<p class='v10'><a href=\"".$ref."\" style=\"font-weight: bold;\">click here to go back</a> (if no automatic redirect)</p>\n"; 246 echo "<script type=\"text/javascript\"> window.location.href = \"".$ref."\"; </script>\n"; 247 248 } else { 249 echo "<p class=\"error\"><strong>error while file take over</strong></p>\n"; 250 echo "<p class='v10'><a href=\"".$ref."\" style=\"font-weight: bold;\">click here to go back</a></p>\n"; 251 } 252 echo "</body>\n</html>\n"; 253 254 255 if(isset($oldumask)) { 256 umask($oldumask); 257 } 258 259 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jan 29 16:31:14 2012 | Cross-referenced by PHPXref 0.7.1 |