$value) { if(intval($ftp["mark"][$key])) { $ftp["file"][$key] = base64_decode($ftp["file"][$key]); } else { unset($ftp["mark"][$key]); unset($ftp["file"][$key]); } } if(!count($ftp["mark"])) $ftp["error"] = 1; } else { $ftp["error"] = 1; } ?> phpwcms: creating thumbnail $value) { unset($ftp["keywords"][$key]); $key = intval($key); if($value != "0_1") { $ftp["keys"] .= (($ftp["keys"]) ? ":" : "").$key."_".intval($value); $ftp["keywords"][$key] = intval($value); } else { $file_error["keywords"][$key] = 1; } } } ?>

 selected files uploaded via ftp will be taken over!

"; flush(); foreach($ftp["mark"] as $key => $value) { if(!ini_get('safe_mode') && function_exists('set_time_limit')) set_time_limit(60); $file = $ftp["file"][$key]; $file_path = PHPWCMS_ROOT.$phpwcms["ftp_path"].$file; if(file_exists($file_path)) { $file_type = ''; $file_error["upload"] = 0; $file_size = filesize($file_path); $file_ext = check_image_extension($file_path); $file_ext = (false === $file_ext) ? which_ext($file) : $file_ext; $file_name = clearfilename( PHPWCMS_CHARSET != 'utf-8' && seems_utf8($file) ? utf8_decode($file) : $file); $file_hash = md5( $file_name . microtime() ); if(trim($file_type) == '') { //check file_type if(is_mimetype_by_extension($file_ext)) { $file_type = get_mimetype_by_extension($file_ext); } else { $file_check = getimagesize($file_path); if(version_compare("4.3.0", phpversion(), ">=") && $file_check) { $file_type = image_type_to_mime_type($file_check[2]); } if(!trim($file_type)) { $file_type = 'application/force-download'; } } } $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) VALUES (". $ftp["dir"].", ".intval($_SESSION["wcs_user_id"]).", 1, ".$ftp["aktiv"].", ".$ftp["public"].", '". aporeplace($file_name)."', '".time()."', '".$file_size."', '".aporeplace($file_type)."', '". aporeplace($file_ext)."', '".aporeplace($ftp["short_info"])."', '". aporeplace($ftp["long_info"])."', '".$ftp["keys"]."', '".$file_hash."', '". aporeplace($ftp["copyright"])."', '".aporeplace($ftp["tags"])."')"; if($result = mysql_query($sql, $db) or die("error while insert file information")) { $new_fileId = mysql_insert_id($db); //Festlegen der aktuellen File-ID $_file_extension = ($file_ext) ? '.'.$file_ext : ''; $wcs_newfilename = $file_hash . $_file_extension; // changed for using hashed file names $userftppath = PHPWCMS_ROOT.$phpwcms["ftp_path"]; $useruploadpath = PHPWCMS_ROOT.$phpwcms["file_path"]; $usernewfile = $useruploadpath.$wcs_newfilename; $oldumask = umask(0); if ($dir = @opendir($useruploadpath)) { if(@copy($userftppath.$file, $usernewfile)) { @unlink($userftppath.$file); // store tags _dbSaveCategories($ftp["tags"], 'file', $new_fileId, ','); } else { $file_error["upload"] = "Error while writing file to storage (1)."; } } } if(empty($file_error["upload"])) { // now try to find 1st file having same named and replace it if related mark is set if($ftp["replace"]) { $rsql = "SELECT * FROM ".DB_PREPEND."phpwcms_file WHERE "; $rsql .= "f_name='".aporeplace($file_name)."' AND f_kid=1 "; $rsql .= "AND f_pid=".$ftp["dir"]." AND f_trash=0 AND f_id != ".$new_fileId." LIMIT 1"; if($rresult = mysql_query($rsql, $db)) { if($rrow = mysql_fetch_assoc($rresult)) { $oldFileID = $rrow['f_id']; $oldFileHash = $rrow['f_hash']; $oldFileNewHash = md5( $file_name . microtime() . time() ); // now update new file by old file information of same named $nsql = "UPDATE ".DB_PREPEND."phpwcms_file SET "; $nsql .= "f_refid=".$oldFileID.", f_trash=5, f_size=".$rrow['f_size'].', '; $nsql .= "f_type='".$rrow['f_type']."', f_changed=".now().', '; $nsql .= "f_hash='".aporeplace($oldFileNewHash)."' WHERE f_id=".$new_fileId; if(mysql_query($nsql, $db)) { // yepp both files are updated in db // now change hash of file storage files rename($useruploadpath.$oldFileHash.$_file_extension, $useruploadpath.$oldFileNewHash.$_file_extension); rename($usernewfile, $useruploadpath.$oldFileHash.$_file_extension); // update file size of old file with new filesize _dbUpdate('phpwcms_file', array('f_type'=>$file_type, 'f_size'=>$file_size, 'f_changed'=>now()), 'f_id='.$oldFileID); //now try to delete all temp images if available $isql = "SELECT imgcache_imgname FROM ".DB_PREPEND."phpwcms_imgcache WHERE imgcache_hash='".aporeplace($oldFileHash)."'"; if($iresult = mysql_query($isql, $db)) { $cImagePath = PHPWCMS_ROOT . '/' . PHPWCMS_IMAGES; while($irow = mysql_fetch_row($iresult)) { if(file_exists($cImagePath.$irow[0])) { @unlink($cImagePath.$irow[0]); } } } } } mysql_free_result($rresult); } } flush(); echo $file." [OK!]
"; } else { echo $file." (".$file_error["upload"].")
"; mysql_query("DELETE FROM ".DB_PREPEND."phpwcms_file WHERE f_id=".$new_fileId." AND f_uid=".$_SESSION["wcs_user_id"], $db); } } else { echo $file." not exists
"; } flush(); } echo "

\n"; } if(empty($file_error["upload"]) && empty($ftp["error"])) { echo "

every selected file was taken over

\n"; echo "

click here to go back (if no automatic redirect)

\n"; echo "\n"; } else { echo "

error while file take over

\n"; echo "

click here to go back

\n"; } echo "\n\n"; if(isset($oldumask)) { umask($oldumask); } ?>