<?
	/**
	 * Allows user to upload a file.
	 *
	 * @author	$Author: suraj $
	 * @version	$Revision: 1.9 $, $Date: 2003/02/11 03:53:39 $
	 */
	//

	require_once("assets/includes/config.inc.php");
	
	// check for path beyond top-most allowed directory
	if(!strstr($path, realpath($cfgVars['BROWSER_ROOT_PATH'])))
	{
		die("The file you have requested is beyond the root folder.");
	}
	
	// start displaying page
	$page_title = $appVars['name'] . " Upload File";
	include("assets/includes/page-header.inc.php");
?>
<script language="javascript" type="text/javascript">
<!--
	function init() {}
//-->
</script>

<h1>Upload File</h1>
<?
	//echo $path;
	//print_r( $HTTP_POST_FILES['upfile'] );
	
	// "none" is returned by HTML form if no file selected
	if(is_array($HTTP_POST_FILES['upfile']) && $HTTP_POST_FILES['upfile'] != "none")
	{
		$destPath = $path;
		
		if(is_dir($destPath))
		{
			$destPath = realpath( $destPath ."/". $HTTP_POST_FILES['upfile']['name'] );
			//echo $destPath;
		}
		
		// copy the temp file
		copy($HTTP_POST_FILES['upfile']['tmp_name'], $destPath) or die("Couldn't copy the file!");

		// delete the temp file
		unlink($HTTP_POST_FILES['upfile']['tmp_name']) or die("couldn't delete temp file.");

		echo "<div class=\"dialog\">File uploaded successfully to <tt>$destPath</tt>.</div>";
	}
	else // display form
	{
?>
	<form enctype="multipart/form-data" method="post" action="<?= $REQUEST_URI ?>">
		<table class="dialog" border="0" cellspacing="0" cellpadding="10">
		<tr>
			<td>
				<div class="warning">
					NOTE: This will overwrite/replace the existing file:<br>
					<tt><?= $path ?></tt>
				</div><br>
				Enter the path of the file that you wish to upload:<br>
				<input class="pathInput" type="file" name="upfile" size="50">
			</td>
		</tr>
		<tr>
			<td>
				Enter the destination path for this file:<br>
				<input class="pathInput" type="text" name="path" size="50" value="<?= $path ?>">
			</td>
		</tr>
		<tr>
			<td align="right">
				<input type="submit" name="upload" value="Upload File">
				<input type="button" name="cancel" value="Cancel" onclick="history.back()">
			</td>
		</tr>
		</table>
	</form>
<?
	}
?>
<p><a href="#" onclick="window.close()">Close Window</a></p>
</body>
</html>
