hi!
inc_ftptakeover.php (include/inc_act/)
now I can upload via ftp and take over the files
GD and thumbnails work too, but "download files" does not
Code: Select all
<?php
/*************************************************************************************
Copyright notice
(c) 2002-2003 Oliver Georgi (oliver@phpwcms.de) // 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!
*************************************************************************************/
session_start();
require_once ("../inc_conf/conf.inc.php");
require_once ("../inc_lib/default.inc.php");
require_once ("../inc_lib/general.inc.php");
require_once ("../inc_lib/checklogin.inc.php");
$ref = $_SERVER['HTTP_REFERER'];
$ftp["error"] = 0;
$ftp["mark"] = $_POST["ftp_mark"];
$ftp["file"] = $_POST["ftp_file"];
if(is_array($ftp["mark"]) && count($ftp["mark"])) {
foreach($ftp["mark"] as $key => $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;
}
?>
<html>
<head><title>phpwcms: creating thumbnail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<link href="../inc_css/phpwcms.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body { background-color: #EBF2F4; }
-->
</style>
</head>
<body bgcolor="#EBF2F4" text="#000000" link="#000000" vlink="#000000" alink="#000000" leftmargin="15" topmargin="15" marginwidth="15" marginheight="15">
<?php
if(!$ftp["error"]) {
$ftp["dir"] = intval($_POST["file_dir"]);
$ftp["short_info"] = clean_slweg($_POST["file_shortinfo"], 250);
$ftp["aktiv"] = intval($_POST["file_aktiv"]);
$ftp["public"] = intval($_POST["file_public"]);
$ftp["thumb"] = intval($_POST["file_thumb"]);
$ftp["long_info"] = clean_slweg($_POST["file_longinfo"],65000);
$ftp["keywords"] = $_POST["file_keywords"];
if(count($ftp["keywords"])) {
$ftp["keys"] = "";
foreach($ftp["keywords"] as $key => $value) {
unset($ftp["keywords"][$key]);
$key = intval($key);
if($value != "0_1") {
$ftp["keys"] .= ((!isEmpty($ftp["keys"])) ? ":" : "").$key."_".intval($value);
$ftp["keywords"][$key] = intval($value);
} else {
$file_error["keywords"][$key] = 1;
}
}
}
if($ftp["thumb"]) include_once ("../inc_lib/imagick.convert.inc.php");
?><p><img src="../../img/symbole/rotation.gif" width="15" height="15"><strong class="title"> selected files uploaded via ftp will be taken over!</strong></p><?php
echo "<p class=\"v10\">";
flush();
foreach($ftp["mark"] as $key => $value) {
if(!ini_get('safe_mode')) set_time_limit(60);
$file = $ftp["file"][$key];
if(file_exists(PHPWCMS_ROOT.$phpwcms["ftp_path"].$file)) {
$file_error["upload"] = 0;
$file_size = filesize(PHPWCMS_ROOT.$phpwcms["ftp_path"].$file);
$file_ext = which_ext($file);
$file_check = getimagesize(PHPWCMS_ROOT.$phpwcms["ftp_path"].$file);
$file_type = image_type_to_mime_type ($file_check[2]);
$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) VALUES (".
$ftp["dir"].", ".$_SESSION["wcs_user_id"].", 1, ".$ftp["aktiv"].", ".$ftp["public"].", '".
clearfilename($file)."', '".time()."', '".
$file_size."', '".$file_type."', '".$file_ext."', '".
aporeplace($ftp["short_info"])."', '".aporeplace($ftp["long_info"])."', '".$ftp["keys"]."');";
if($result = mysql_query($sql, $db) or die("error while insert file information")) {
$new_fileId = mysql_insert_id(); //Festlegen der aktuellen File-ID
$wcs_newfilename = $_SESSION["wcs_user_id"]."_".$new_fileId;
if(!isEmpty($file_ext)) $wcs_newfilename .= ".".$file_ext;
$useruploadpath = PHPWCMS_ROOT.$phpwcms["file_path"];
$userftppath = PHPWCMS_ROOT.$phpwcms["ftp_path"];
$usernewfile = $useruploadpath."/".$wcs_newfilename;
if ($dir = @opendir($useruploadpath)) {
if(@copy($userftppath.$file, $usernewfile)) {
@unlink($userftppath.$file);
} else {
$file_error["upload"] = "Error while writing file to storage (1).";
}
} else {
$oldumask = umask(0);
if(@mkdir($useruploadpath, 0777)) {;
if(@copy($userftppath.$file, $usernewfile)) {
@unlink($userftppath.$file);
} else {
$file_error["upload"] = "Error while writing file to storage (2).";
}
} else {
$file_error["upload"] = "Error while creating user directory.";
}
umask($oldumask);
}
}
if(!$file_error["upload"]) {
flush();
//Nur Vorschau für übereinstimmende Dateiendung anlegen
if(is_ext_true(strtolower($file_ext)) && $ftp["thumb"] && gd_image_check($usernewfile)) {
if(!ini_get('safe_mode')) set_time_limit(90);
// Prevent user from aborting script
$old_abort = ignore_user_abort(true);
$dir_thumb_list = PHPWCMS_ROOT."/".$phpwcms["file_tmp"].$phpwcms["dir_thlist"];
$dir_thumb_prev = PHPWCMS_ROOT."/".$phpwcms["file_tmp"].$phpwcms["dir_preview"];
$thumb_add = "_".generic_string(10);
//Preview Bild erzeugen
$create_preview = imagick_convert($wcs_newfilename,"jpg",$thumb_add,$useruploadpath."/",$dir_thumb_prev,$phpwcms["img_prev_width"],$phpwcms["img_prev_height"]);
//check if file really exists after ImageMagick function -> maybe no error reported
if(!file_exists($dir_thumb_prev.$create_preview["image_thumb_name"])) $create_preview["error"] = "no thumbnail exists";
if(!$create_preview["error"]) {//create list thumbnail
$create_listthumb = imagick_convert($create_preview["image_thumb_name"],"jpg","",$dir_thumb_prev,$dir_thumb_list, $phpwcms["img_list_width"], $phpwcms["img_list_height"]);
}
//If successful then update thumbnail image names in database
//if(!$create_preview["error"] || !$create_listthumb["error"]) {
if(!$create_preview["error"]) {
$sql = "UPDATE ".DB_PREPEND."phpwcms_file SET ";
//changed because -> set no thumbnail to empty string
$sql .= "f_thumb_preview='".aporeplace($create_preview["image_thumb_name"])."', ";
$sql .= "f_thumb_list='".aporeplace($create_listthumb["image_thumb_name"])."' ";
$sql .= "WHERE f_id=".$new_fileId." AND f_uid=".$_SESSION["wcs_user_id"].";";
mysql_query($sql , $db) or die("error while update thumbnail informations");
} else {
$sql = "UPDATE ".DB_PREPEND."phpwcms_file SET ";
$sql.= "f_thumb_preview='', f_thumb_list='' ";
$sql .= "WHERE f_id=".$new_fileId." AND f_uid=".$_SESSION["wcs_user_id"].";";
mysql_query($sql , $db) or die("error while update thumbnail informations");
}
// Reset abort setting
ignore_user_abort($old_abort);
}
echo $file." [OK!]<br>";
} else {
echo $file." (".$file_error["upload"].")<br>";
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<br>";
}
flush();
}
echo "</p>\n";
}
if(!$file_error["upload"] && !$ftp["error"]) {
echo "<p class=\"title\"><strong>every selected file was taken over</strong></p>\n";
echo "<p class='v10'><a href=\"".$ref."\" style=\"font-weight: bold;\">click here to go back</a> (if no automatic redirect)</p>\n";
echo "<script language=\"JavaScript\" type=\"text/javascript\">\n<!--\n";
echo "window.location.href = \"".$ref."\";\n//-->\n</script>\n";
} else {
echo "<p class=\"error\"><strong>error while file take over</strong></p>\n";
echo "<p class='v10'><a href=\"".$ref."\" style=\"font-weight: bold;\">click here to go back</a></p>\n";
}
echo "</body>\n</html>\n";
?>