Ich wollt fragen ob es möglich wäre bei diesem Skript unter meinem Text einen Schutz reinzumachen der nur .gif und .jpg und .jpeg und viell. noch andere erlaubt?



Code: Alles auswählen
<?php
// CSS-Style:
$cssstyle =
'<style type="text/css"><!--
a:link{color:#000000;}
a:visited{color:#999999;}
a:hover{color:#999999;}
a:active{color:#f999999;}
--></style>';
//**************************************************************
// Programm:
//**************************************************************
echo "$cssstyle";
// Links on Top
head();
// Startsite
// Get $path & $action
if ($SubmitDir || $SubmitUpload)
{$path = $chosenpath;}
else
{$path = $_GET["path"];}
$action = $_GET["action"];
// choose downloadpath
if ($action == "download" && $path == '')
{
$all_dirs = get_all_dirs();
choose_download_dir($all_dirs);
}
// choose downloadfile
if ($action == "download" && $path != '')
{
$all_dirs = get_all_dirs();
choose_download_dir($all_dirs);
$all_files = listen_dir($path);
choose_download($all_files, $path);
}
// choose upload
if ($action == "upload" && !$SubmitUpload)
{
$all_dirs = get_all_dirs();
choose_upload($all_dirs);
}
// do upload
if ($SubmitUpload)
{
upload($path);
}
// Links on bottom
foot();
//**************************************************************
// Functions:
//**************************************************************
function head()
{
echo '
<html>
<head>
<title>Upload/Download</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<font face="tahoma">
<div align="center"> <a href="';
echo "$PHP_SELF";
echo '?action=">Startseite</a> | <a href="';
echo "$PHP_SELF";
echo '?action=download">Download</a>
| <a href="';
echo "$PHP_SELF";
echo'?action=upload">Upload</a> </div>
';
}
function foot()
{
echo '
</font>
</body>
</html>
';
}
function choose_download_dir($all_dirs)
{
echo '<br><div align="center">';
echo "Choose Directory for Download:";
echo '<form name="form1" method="post" action="';
echo "$PHP_SELF?action=download";
echo '">';
echo '<select name="chosenpath">';
for ($i = 0; $i < count($all_dirs); $i++)
{
echo '<option>';
echo "$all_dirs[$i]";
echo '</option>';
}
echo '</select>';
echo ' ';
echo '<input type="submit" name="SubmitDir" value="Choose" class="SB_button">';
echo '</form></div>';
}
function choose_download($all_files, $path)
{
echo '<table width="90%" border="0" align="center" bordercolor="#000000">
<tr>
<td><font face=tahoma size=2><b>Filename:</b></font></td>
<td><font face=tahoma size=2><b>Size:</b></font></td>
<td><font face=tahoma size=2><b>Date:</b></font></td>
</tr>
<tr>
<td><font face=tahoma size=2></font></td>
<td><font face=tahoma size=2></font></td>
<td><font face=tahoma size=2></font></td>
</tr>';
for ($i = 0; $i < count($all_files); $i++)
{
if ($bgcolor == "#CCCCCC") {$bgcolor = "#FFFFFF";}
else {$bgcolor = "#CCCCCC";}
$file = $path . "/" . $all_files[$i];
$file_date = @date("d.m.Y", filemtime($file));
$file_size = (int)(filesize($file)/2048);
if ($file_date == "01.01.1970") {$file_date = "-";}
echo "<tr bgcolor=$bgcolor>
<td><font face=tahoma size=2><a href=$file>$all_files[$i]</a></font></td>
<td><font face=tahoma size=2>$file_size KB</font></td>
<td><font face=tahoma size=2>$file_date</font></td>";
}
echo '</table>';
}
function listen_dir($dir)
{
$dir .= "/";
if (file_exists($dir))
{
!$opendir = opendir($dir);
$i = 0;
while ($file = readdir($opendir))
{
$ext = strrchr($file,'.');
if ($ext != '' && $file != '.' && $file != '..')
{
$all_files[$i] = $file;
$i++;
}
}
closedir($opendir);
return $all_files;
}
}
function get_all_dirs()
{
$verz=opendir ('.');
$i = 0;
while ($file = readdir ($verz))
{
if(is_dir($file) && $file != "." && $file != "..")
{
$all_dirs[$i] = $file;
$i++;
}
}
closedir($verz);
return $all_dirs;
}
function choose_upload($all_dirs)
{
echo '<br><div align="center">';
echo "Choose Directory for Upload:";
echo '<form enctype="multipart/form-data" name="form1" method="post" action="';
echo "$PHP_SELF?action=upload";
echo '">';
echo '<select name="chosenpath">';
for ($i = 0; $i < count($all_dirs); $i++)
{
echo '<option>';
echo "$all_dirs[$i]";
echo '</option>';
}
echo '</select>';
echo '<p>Choose File for Upload:<p>';
for ($i = 0; $i <5; $i++)
{
echo '<input type="file" name="uploadfile';
echo "$i";
echo' "><br>';
}
echo '<p><input type="submit" name="SubmitUpload" value="Upload" class="formbutton">';
echo '</form></div>';
}
function upload($path)
{
echo "<p>";
foreach ($_FILES as $upfile_info) {
if (($file_name=$upfile_info['name'])!='') {
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$dest_location=$path."/".$file_name;
$ext = strrchr($file_name,'.');
if (!file_exists($dest_location) && ($ext != ".php"))
{
$copy = copy($upfile_info['tmp_name'], $dest_location);
}
else {$MSG = "File already exists or Fileextension not allowed!";}
$type=$upfile_info['type'];
$size=(int)($upfile_info['size']/1024);
$MSG="<b>$dest_location</b> (mime: $type | size: $size KB)";
echo "<div align=center><font size=2>Successfully uploaded file: $MSG</font></div><br>";
}
}
}
?>