<?
header('Content-type: text/plain');




if (!$permissions['upload']) {
	echo $lang->get("You are not allowed to upload files");
	exit();
}

if (!isCleanPath($topath)) {
	echo  $lang->get('Ilegal path: ').$topath;
	exit();
}

if ($permissions['unlimitedTraffic'] == false && $quota->canAddTraffic() == false) {
	echo $lang->get("Traffic quota excedeed");
	exit();
}

if (!is_dir($sys['fullPath'])) {
	echo $lang->get("The folder where you want to upload files does not exist any more.");
	exit();
}



for ($i=0 ; $i < sizeof($_FILES) ; $i++) {
	$uploadFilename = $_FILES["File".$i]['tmp_name'];
	$niceFilename = $_FILES["File".$i]['name'];
	$niceFilename = $str->fromHTML($niceFilename);
	$toFile = gluePath($sys['fullPath'],$niceFilename);
	$filesize = $_FILES["File".$i]['size'];

	if ($HTTP_POST_FILES['uploadfiles']['error'][$i] && $niceFilename != "") {
		echo $lang->get("Maximum upload limit reached. File \"%1\" could not be uploaded.", array($niceFilename));
	}
	if ($permissions['unlimitedSpace'] || $userHaveFreeSpace) {
		if (is_uploaded_file($uploadFilename)) {
		if ($fm->copyFile($uploadFilename, $toFile)) {
		$userHaveFreeSpace = recalcUsedSpace();
		//addTraffic($filesize);
		//$log->act("0", "upload", $toFile);
		//$log->lastUpload($toFile);
		echo $niceFilename." ......... OK\n";

		if ($options['uploadNotice'] && $config->settings['adminemail']) {
			$mail = new htmlMimeMail();
			$message = "\n";
			$message .= "User \"".$completeUserInfo['username']."\" uploaded:\n";
			$message .= "Date: " . date("d/n/Y H:i") ."\n";
			$message .= "Filename: " . $niceFilename ."\n";
			$message .= "Filesize: " . $fm->formatFileSize(@filesize($toFile)) ."\n";
			$message .= "Uploaded to folder: " . $sys['fullPath'] ."\n";
			$mail->setText($message);
			$mail->setFrom(($sys['license']['unbranded']?$sys['license']['unbranded']:"Afian"));
			$mail->setSubject("Upload from ".$completeUserInfo['username']);
			$result = $mail->send(array($config->settings['adminemail']));
		}
		
		} else {
		if (file_exists($toFile)) {
		echo $lang->get("Upload failed: '%1' already exists.\n", array(gluePath($tofolder, $niceFilename)));
		}
		//$log->act("1", "upload", $toFile." (".$fm->errorMsg.")");
		}
		
	} else {
		echo $lang->get("Not enough space available to upload '%1'\n", array($niceFilename));
	}

}
?>