Skal ikke vise bestemte fil typer
Jeg sider med et upload, den bruges til at uploade filer til en DIR mappe, der oxo bruges til min WAP side, den viser oxo ( *.php ) filer hvilken den helst ikke skal, Er der en der gider hjælpe mig med det vil jeg blive meget glad.....>>>>>>>>>>>>>>>>>>>>>>>
<?php
#---------------------------------------#
# file upload manager 1.2
# 24.04.2003
#
# written by thepeak
# copyright (c) 2003 thepeak of mtnpeak.net
#
# www: http://webdev.mtnpeak.net
# www: http://www.xd3v.com
# email: thepeak@gmx.net
#
# A simple, powerful tool to upload and
# manage files using your web browser.
#
# This program 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, as long as the
# copyright info and links stay intact. You may not sell
# this program under any circumstance without written
# permission from the author.
#
# please send me feedback - and enjoy!
#---------------------------------------#
################## config ####################
# header & title of this file
$title = "File Upload Manager";
# individual file size limit - in bytes (102400 bytes = 100KB)
$file_size_ind = "256000";
# the upload store directory (chmod 777)
$dir = "Temp";
# the style-sheet file to use (located in the "img" directory, excluding .css)
$style = "style-def";
# the file type extensions allowed to be uploaded
$file_allow_ex = array("gif","jpg","jpeg","png","txt","nfo","doc","rtf","htm","zip","rar","gz","exe");
# option to display the file list
# to enable/disable, enter "yes" or "no" (CASE SENSITIVE)
$file_list_allow = "yes";
# option to allow file deletion
# to enable/disable, enter "yes" or "no" (CASE SENSITIVE)
$file_del_allow = "no";
# option to password-protect this script [-part1]
# to enable/disable, enter "yes" or "no" (CASE SENSITIVE)
$auth_ReqPass = "no";
# option to password-protect this script [-part2]
# if you set $auth[ReqPass] to "yes", then you must set the username and password
$auth_usern = "Crapmaster";
$auth_passw = "271272";
################# /config ####################
?>
<?
if($auth_ReqPass == "yes") {
function error ($error_message) {
echo $error_message."<br>";
exit;
}
if ( (!isset($PHP_AUTH_USER)) || ! (($PHP_AUTH_USER == $auth_usern) && ( $PHP_AUTH_PW == "$auth_passw" )) ) {
header("WWW-Authenticate: Basic entrer=\"file upload manager\"");
header("HTTP/1.0 401 Unauthorized");
error("Access Denied! You must enter a valid username & password.");
}
}
clearstatcache();
@include_once("http://www.mtnpeak.net/webdev/fileupload/curr_vers.inc");
$fum_vers = "1.2"; # do not edit this, the script will not work!!!
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><? echo ($title) ? ($title) : ("File Upload Manager"); ?></title>
<link rel="stylesheet" href="img/<?=$style?>.css" type="text/css">
</head>
<body bgcolor="#F7F7F7"><br><br>
<center>
<table width="560" cellspacing="0" cellpadding="0" border="0">
<tr>
<td><font size="3"><b><i><? echo ($title) ? ($title) : ("File Upload Manager"); ?></i></b></font> <font style="text-decoration: bold; font-size: 9px;">v<?=$fum_vers?></font>
<?
#--Please do not remove my link/copyright as it is unfair and a breach of the license--#
echo"<a href=\"http://www.mtnpeak.net\" style=\"text-decoration: none; color: #C0C0C0; font-size: 9px; cursor: default\";>© thepeak</a>";
?>
</td>
</tr>
</table>
<?
function getlast($toget)
{
$pos=strrpos($toget,".");
$lastext=substr($toget,$pos+1);
return $lastext;
}
function replace($o)
{
$o=str_replace("/","",$o);
$o=str_replace("\\","",$o);
$o=str_replace(":","",$o);
$o=str_replace("*","",$o);
$o=str_replace("?","",$o);
$o=str_replace("<","",$o);
$o=str_replace(">","",$o);
$o=str_replace("\"","",$o);
$o=str_replace("|","",$o);
return $o;
}
if(!eregi("777",decoct(fileperms($dir))))
{
echo"<br><br><b><h4><font color=\"FF0000\">ERROR: cannot access file directory. please chmod directory \"$dir\" with value 777 (xrw-xrw-xrw)!</h4></font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">refresh</a>";
}
else
{
if(!$_FILES[fileupload])
{
?>
<table width="560" cellspacing="0" cellpadding="0" border="0" class="table_decoration" style="padding-top:5px;padding-left=5px;padding-bottom:5px;padding-right:5px">
<form method="post" enctype="multipart/form-data">
<tr>
<td>file:</td><td><input type="file" name="fileupload" class="textfield" size="30"></td>
</tr>
<tr>
<td>rename to:</td><td><input type="text" name="rename" class="textfield" size="46"></td>
</tr>
<tr>
<td>file types allowed:</td><td><?
for($i=0;$i<count($file_allow_ex);$i++)
{
if(($i<>count($file_allow_ex)-1))$commas=", ";else $commas="";
list($key,$value)=each($file_allow_ex);
echo $value.$commas;
}
?></td>
</tr>
<tr>
<td>file size limit:</td><td><?=$file_size_ind?> BYTES (<b><?=round(($file_size_ind/1024),2)?> KB</b>, <?=round(($file_size_ind/1024000),3)?> MB)</b></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="upload" class="button"> <input type="reset" value="clear" class="button"></td>
</tr>
</form>
</table>
<?
if((!$_GET[act]||!$_GET[file])&&$_GET[act]!="delall")
{
$opendir = @opendir($dir);
while ($readdir = @readdir($opendir))
{
if($readdir<>"." && $readdir<>".." && $readdir != "index.html")
{
$filearr[] = $readdir;
}
$sort=array();
for($i=1;$i<=count($filearr);$i++)
{
$key = sizeof($filearr)-$i;
$file = $filearr[$key];
$sort[$i]=$file;
}
asort($sort);
}
if(count($filearr)>=1)
{
if(count($filearr)>1)
{
?>
<br>
<table width="560" cellspacing="0" cellpadding="0" border="0" class="table_decoration" style="padding-left:5px">
<tr>
<td><b>admin tools:</b> <? if($file_del_allow == "yes") { ?><a href="java script:;" onClick="cf=confirm('Are you sure you want to delete ALL FILES?');if(cf)window.location='?act=delall'; return false;" style="font-size: 9px;"><delete all files></a> | <? } elseif($file_list_allow !== "yes") { echo""; } else { echo""; } ?><a href="java script:;" onClick="alert('The current version of File Upload Manager available is: <? echo ($fum_curr_vers) ? ($fum_curr_vers) : ("not known"); ?>\nYou are running version <?=$fum_vers?>\nYou can download it from http://webdev.mtnpeak.net')" style="font-size: 9px;"><current version></a>
</td>
</tr>
</table>
<br>
<?
}
else
{
echo"<br>";
}
if($file_list_allow == "yes") {
?>
<table width="560" cellspacing="0" cellpadding="0" border="0" class="table_decoration" style="padding-left:6px">
<tr bgcolor="#DBDBDB">
<td align="left" width="46%">FILENAME</td>
<td align="center" width="12%">FILE TYPE</td>
<td align="center" width="12%">FILE SIZE</td>
<td align="center" width="30%">FUNCTIONS</td>
</tr>
<?
for($i=1;$i<=count($sort);$i++)
{
list($key,$value)=each($sort);
if($value)
{
$value_en=base64_encode($value);
?>
<tr>
<td width="30%"><?="<a href=\"?act=view&file=$value_en\">$value</a>"?></td>
<td align="center" width="5%"><? echo strtoupper(getlast($value)); ?></td>
<td align="center" width="5%">
<?
$value_full = "$dir/$value";
$file_size = filesize($value_full);
if ($file_size >= 1073741824) {
$show_filesize = number_format(($file_size / 1073741824),2) . " GB";
} elseif ($file_size >= 1048576) {
$show_filesize = number_format(($file_size / 1048576),2) . " MB";
} elseif ($file_size >= 1024) {
$show_filesize = number_format(($file_size / 1024),2) . " KB";
} elseif ($file_size >= 0) {
$show_filesize = $file_size . " bytes";
} else {
$show_filesize = "0 bytes";
}
echo "$show_filesize";
?></td>
<td align="center" width="5%"><?="<a title=\"View File\" href=\"?act=view&file=$value_en\"><view></a>"?> | <? if($file_del_allow == "yes") { ?><?="<a title=\"Download file\" href=\"?act=dl&file=$value_en\"><dl></a>"?><? } else { echo"<a title=\"Download file\" href=\"?act=dl&file=$value_en\"><download></a>"; } ?><? if($file_del_allow == "yes") { ?> | <?="<a title=\"Delete file\" href=\"java script:;\" onClick=\"cf=confirm('Are you sure you want to delete this file?');if(cf)window.location='?act=del&file=$value_en'; return false;\"><delete></a>"?><? } else { echo""; } ?></td>
</tr>
<?
}
else
{
echo"<br>";
}
}
}
?>
</table></center>
<?
}
}
elseif(($_GET[act]=="del")&&$_GET[file])
{
$value_de=base64_decode($_GET[file]);
@unlink($dir."/$value_de");
echo"<br><img src=\"img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">file has been deleted!</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
}
elseif(($_GET[act]=="view")&&$_GET[file])
{
$value_de=base64_decode($_GET[file]);
echo"<script language=\"javascript\">window.open(\"$dir/$value_de\", \"fum_viewfile\", \"resizable=yes,width=640,height=480,scrollbars=yes,status=no\")</script>";
echo"<br><img src=\"img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">file opened!</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a><br><br><br>If this file did not display, you must <b>disable</b> your popup manager or enable javascript in your browser.";
}
elseif(($_GET[act]=="dl")&&$_GET[file])
{
$value_de=base64_decode($_GET[file]);
echo"<body onMouseOver=\"window.status='';return true;\">" . "<br><a href=\"$dir/$value_de\">Right click here to download \"$value_de\"</a>" . "<br><br>" . "<b>IE Users</b> - right click link above & select SAVE TARGET AS" . "<br><b>Netscape Users</b> - right click link above & select SAVE LINK AS" . "<br><b>Mozilla Users</b> - right click link above & select SAVE LINK TARGET AS" . "<br><b>Opera Users</b> - right click link above & select SAVE TARGET AS" . "<br><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a><br><br>";
}
if($_GET[act]=="delall")
{
$handle=opendir($dir);
while($file=readdir($handle))
if(($file != ".")&&($file != ".."))
@unlink($dir."/".$file);
closedir($handle);
echo"<br><img src=\"img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">all files have been deleted!</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
}
}
else
{
echo"<br><br>";
$uploadpath=$dir."/";
$source=$_FILES[fileupload][tmp_name];
$fileupload_name=$_FILES[fileupload][name];
$weight=$_FILES[fileupload][size];
for($i=0;$i<count($file_allow_ex);$i++)
{
if(getlast($fileupload_name)!=$file_allow_ex[$i])
$test.="~~";
}
$exp=explode("~~",$test);
if(count($exp)==(count($file_allow_ex)+1))
{
echo"<br><img src=\"img/error.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">ERROR: your file type is not allowed (".getlast($fileupload_name).")</font>, or you didn't specify a file to upload.</b><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
}
else
{
if($weight>$file_size_ind)
{
echo"<br><img src=\"img/error.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">ERROR: please get the file size less than ".$file_size_ind." BYTES (".round(($file_size_ind/1024),2)." KB)</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
}
else
{
foreach($_FILES[fileupload] as $key=>$value)
{
echo"<font color=\"#3399FF\">$key</font> : $value <br>";
}
echo "<br>";
$dest = '';
if ( ($source != 'none') && ($source != '' ))
{
$dest=$uploadpath.$fileupload_name;
if ($dest != '')
{
if(file_exists($uploadpath.$fileupload_name))
{
echo"<br><img src=\"img/error.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">ERROR: that file has already been uploaded before, please choose another file</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
}
else
{
if (copy($source,$dest))
{
if($_POST[rename])
{
$_POST[rename]=replace($_POST[rename]);
$exfile=explode(".",$fileupload_name);
if(@rename("$dir/$fileupload_name","$dir/$_POST[rename].".getlast($fileupload_name))) {
echo"<br><img src=\"img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">file has been renamed to $_POST[rename].".getlast($fileupload_name)."!</font></b></font><br>";
}
}
echo"<br><img src=\"img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">file has been uploaded!</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
}
else
{
echo"<br><img src=\"img/error.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">ERROR: cannot upload, please chmod the dir to 777</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
}
}
}
}
}
}
}
}
?>
</body>
</html>
<!-- Copyright (c) 2003 thepeak. Get your own copy of this free PHP script from www.mtnpeak.net -->
