Location: PHPKode > scripts > AskPeople-Free PHP survey application > AskPeople_2_2_2/templates/images/index.php
<?php

### CONFIGURATION:
# files to be ignored in the listing (mainly hidden, authentication files)
$ignorefiles = array(".","..","index.php",".htaccess");

#server/directories:
$server = $_SERVER['HTTP_HOST']; 
$dir = "templates/images"; // this directory

$title = "File Manager";
$version = 2.1;

//$allowedtypesarray = array("application/vnd.ms-powerpoint","application/msword","application/vnd.ms-excel","application/pdf","text/plain","text/html","image/jpeg","image/gif","image/png");

# cookie to access, to get user access details etc
$logincookie = "askpeople_portcullis";

# authentication module (looks for users in a users.inc.php file)
$authentication = "TRUE";
if ($authentication == "TRUE") {
	//require_once('../../login.inc.php');
	//$logoutlink = "<a href=\"../../login.inc.php?logout=true\">Logout</a> | ";
    if (!$_COOKIE[$logincookie]) {
    	die("Sorry, you are not authorised to access this area.");
    }
}

/*
<html>
<head>
<meta name="robots" content="none" /> <!-- Not to be indexed by public search engines -->
<style type="text/css">
<!--
body {
	margin: 0;
	font-family: Arial,Verdana,Helvetica,sans-serif;
	font-size: 0.95em;
	text-align: center;
}

h1 {
	font-size: 135%;
	margin: 5px 0;
}

h3 {
	font-size: 120%;
	margin: 5px 0;
	color: #333;
}

#container {
	margin: 10px auto;
	padding: 5px;
	width: 90%;
	text-align: left;
}

#upload {
  background: #eef;
  border: 1px solid #ccf;
  margin-top: 20px;
  padding: 10px;
}

#downloads {
  background: #fee;
  border: 1px solid #fcc;
  padding: 10px;
}

td {
  text-align: center;
}

td.filename {
  text-align: left;
}

-->
</style>

<script type="text/javascript">//<![CDATA[

function confirmSubmit(message)
{
var agree=confirm(message);
if (agree)
	return true ;
else
	return false ;
}
//]]>
</script>

</head>
<body>
<div id="container">
<?php


if ($authentication == "TRUE") {
	$userinfo = unserialize(stripslashes($_COOKIE[$logincookie]));
	echo "<!--\n";
	print_r($userinfo);
	echo "\n-->";
}
*/

// build list of files in the /files dir
$filelist = "<div id=\"links\" class=\"bluebox\"><h3>Files:</h3><ul>\n";

if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) { 
        if (!in_array($file,$ignorefiles)) { 
        	$fullfile = $dir . $file;
        	$filesize = number_format((@filesize($fullfile))/1000) . "K";
            $filemtime = date("d-M-Y",@filemtime($fullfile));
            $filename = str_replace($fileendings,"",$file); 
            $filelist .= "<li><a href=\"$dir/$file\" title=\"$filename [$filesize, $filemtime]\">$filename</a></li>\n"; 
        } 
    }
    closedir($handle); 
}

$filelist .= "</ul></div>\n";

if ($_REQUEST['action'] == "upload") { // handle file upload

	$error = FALSE;
	
	if (strlen($_FILES['userfile']['tmp_name'])<1) {
		$error = TRUE;	
		$errormsg .= "<p>No file selected.</p><p><a href=\"{$PHP_SELF}?action=admin\">Try again</a></p>";
	} elseif ($_FILES['userfile']['size'] > 20000000) { // file too big (more than 20mb)
		$error = TRUE;
		$errormsg .= "<p>The file you uploaded was larger than the maximum allowed size. It is " . number_format($_FILES['userfile']['size']/1024) . "k, Maximum allowed is 10,000k.</p>";
	} elseif (is_array($allowedtypesarry) && !in_array($_FILES['userfile']['type'],$allowedtypesarray)) { // image not a legal format
		$error = TRUE;
		$errormsg .= "<p>The file you tried to upload is not allowed. Uploaded files must be Word, Excel, Powerpoint, PDF, HTML, plain text, or GIF/JPEG only</p><p><a href=\"{$PHP_SELF}?action=admin\">Try again</a></p>";
	}
	
	//print_r($_FILES);
	
	if (!$error) {
		$dodgychars = array(" ","/","?","&",":",";","*",">","<","[","]");
		$fullfilename = $dir . "/" . str_replace($dodgychars,"_",$_FILES['userfile']['name']);
		$fullfilename = eregi_replace("_+","_",$fullfilename);
				
		copy($_FILES['userfile']['tmp_name'],$fullfilename);
		@unlink($_FILES['userfile']['tmp_name']);
		$html .= "<p>Thank you, that file was uploaded</p>
		<p><a href=\"{$PHP_SELF}\">View the list of files</a></p>";

	} else {
		$html .= $errormsg;
	}
	
} elseif ($_REQUEST['action'] == "admindelete") { // delete a file

	$success = false;
	
	$file = urldecode($_GET['file']);
	
	if (file_exists($file)) {
		unlink($file);
		$success = true;
	} else {
		$success = false;
	}
	
	if ($success) {
		$html .= "<p>Thank you. That file has been removed.</p><p><a href=\"filemgr.php\">View the updated file list</a></p>";
	} else {
		$html .= "<p>Sorry, that file could not be removed.</p><p><a href=\"filemgr.php?action=admin\">Try again</a></p>";	
	}

} else { // present admin and upload screen
	
	$server=$_SERVER['HTTP_HOST']; 

	$delfilelist = "<div id=\"downloads\"><h3>Files:</h3><table class=\"simpletable\" width=\"95%\"><thead><th>Link to file:</th><th width='20%'>File info:</th><th width='10%'>Delete:</th></thead><tbody>\n";

	if ($handle = opendir("$dir/")) {
	    while (false !== ($file = readdir($handle))) { 
	        if (!in_array($file,$ignorefiles)) { 
    	    	$fullfile = $dir . "/" . $file;
    	    	$filesize = number_format((@filesize($fullfile))/1000) . "K";
    	        $filemtime = date("d-M-Y",@filemtime($fullfile));
     	        $fullfilename = urlencode($fullfile);
     	        //$backgroundpreview = (eregi(".jpg",$file) || eregi(".gif",$file)) ? " style='background: url(\"{$dir}/{$file}\") no-repeat right;'" : "";
    	        $delinfo = ($authentication == "FALSE" || $cookieinfo[level] > 7) ? "<td style='text-align:center;'><a onclick=\"return confirmSubmit('This will permanently erase this file. Do you wish to continue?')\" href=\"{$PHP_SELF}?file={$fullfilename}&action=admindelete\" title=\"$file\"><img src=\"http://www.pentri.com/assets/delete-15x15.gif\" alt=\"delete\" border=\"0\" /></a></td>" : "<td>-</td>";
    	        
    	        $delfilelist .= "<tr>
    	        <td{$backgroundpreview} class=\"filename\"><a href=\"{$dir}/{$file}\" target=\"_blank\">$file</a></td>
    	        <td>$filesize, $filemtime</td>
				{$delinfo}
    	        </tr>\n"; 
    	    } 
    	}
    	closedir($handle); 
	}

	$delfilelist .= "</tbody></table></div>\n";

	if ($authentication == "FALSE" || $cookieinfo['level']>5) {
		$uploadbox = "
		<div id=\"upload\">
		<h3>Upload a file:</h3>
		<form enctype=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">
			<p>Choose a file to upload: <input name=\"userfile\" type=\"file\"><input type=\"submit\" value=\"Upload File\"></p>
			<input type=\"hidden\" name=\"action\" value=\"upload\" />
		</form>
		</div>";
	}
	$html .= "
	<br />
	{$delfilelist}
	{$uploadbox}"
	;
	
}

$html .= "<p style=\"text-align:center;\">{$logoutlink}File Manager {$version} by <a href=\"http://www.pentri.com\">Pentri.com</a></p>";

echo ($html);
/*
</div>
</body>
</html>
*/
?>
Return current item: AskPeople-Free PHP survey application