ftp / web uplaod error plz help

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
cartman
Posts: 18
Joined: Tue 18. Nov 2003, 19:38
Contact:

ftp / web uplaod error plz help

Post by cartman »

Hy all!

Sorry for my bad English :D

I wanna make a SouthPark fan site, ( http://free.srv.hu/c/a/cartman/cartman/ but the file upload doesn't work! All the dir permissions are set properly. The server has no restrictions, so I just cannot understand what the problem could be! I just get an error message when trying to upload sg:
Error while creating user directory.

Please do not try again - this is an server error! Contact the webmaster to tell as soon as possible!
plz help! without these function (image upload...) the portal is less usefoul :(

any ideas?

gergő
Last edited by cartman on Sat 22. Nov 2003, 17:35, edited 1 time in total.
cartman
Posts: 18
Joined: Tue 18. Nov 2003, 19:38
Contact:

Post by cartman »

is there a way to view detailed error messages?
cartman
Posts: 18
Joined: Tue 18. Nov 2003, 19:38
Contact:

Post by cartman »

Yuppie! Problem solved! I had to modify some files in the inc dir, to disable user level directory handling. and now it WORKS!
phpwcms rules!
tom_f
Posts: 2
Joined: Tue 11. Nov 2003, 23:04

Gratulation

Post by tom_f »

Could you please describe which files you had to modify, maybe other people are trying to solve the same Problem - Thanks :wink:
Der Müllmann ist da.
Sag ihm, wir brauchen nichts.
(The Marx Brothers)
User avatar
Oliver Georgi
Site Admin
Posts: 9907
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

This can be a problem of umask and such things on safe_mode accounts.
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

I would love to know what you did to fix this problem

Post by pSouper »

Hi Guys,
I would love to know what you did to fix this problem as I am experiencing the same error messages.
thanks pSouper
cartman
Posts: 18
Joined: Tue 18. Nov 2003, 19:38
Contact:

Post by cartman »

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">&nbsp;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";
?>
cartman
Posts: 18
Joined: Tue 18. Nov 2003, 19:38
Contact:

Post by cartman »

and when I'm trying to download the file, I get an error page, and the system logs me off, so i have to logon again, maybe a userid problem?
Last edited by cartman on Sat 22. Nov 2003, 17:36, edited 1 time in total.
User avatar
Oliver Georgi
Site Admin
Posts: 9907
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

What did you change? Please comment!!!
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
cartman
Posts: 18
Joined: Tue 18. Nov 2003, 19:38
Contact:

Post by cartman »

this was the original:

Code: Select all

	$useruploadpath = PHPWCMS_ROOT.$phpwcms["file_path"].$_SESSION["wcs_user_id"];
				$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).";
					}

and this is the modified

Code: Select all

	$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).";
					}

I deleted only : (in the first line)

Code: Select all

.$_SESSION["wcs_user_id"]
User avatar
Oliver Georgi
Site Admin
Posts: 9907
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

This is wrong. It is simpler to create a new folder with your user-ID in filestorage path. The $_SESSION... is needed. When you download your download gives error and ends your session.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
cartman
Posts: 18
Joined: Tue 18. Nov 2003, 19:38
Contact:

Post by cartman »

ok. what is the default webmaster id?
cartman
Posts: 18
Joined: Tue 18. Nov 2003, 19:38
Contact:

Post by cartman »

thx a lot, it works!!!!
Florian
Posts: 119
Joined: Wed 19. Nov 2003, 16:50
Location: Hamburg
Contact:

Post by Florian »

hey there,

got the same problem - fixed by the discribed workaround above.
I've turned Safemode at my systems on, too. To me it seems, that the folder is set with the right right permissions (777), but not "really" (wrong group).
I will try to write a bugfix for that on Safemode systems. But first I have to fix my RAID5 in which crashed 4 of 5 HD's in case of an demaged fan... mega fu** will never ever have one of this damn 15k/rpm HD's again :cry:

Cheers,
Florian
Post Reply