| px | top | add code | search | signup | login | help |
<?php
while(list($key,$value)= each($_GET))
{
eval("$\$key = \"$value\";");
}
while(list($key,$value)= each($_POST))
{
eval("$\$key = \"$value\";");
}
/* This function returns the position of string s1 within string s2.
The position is 1 based. If s1 is not in s2, 0 is returned.
*/
function InStr($s1, $s2)
{
//Check for valid input
if(!(is_string($s1) && is_string($s2))) return 0;
$s1len = strlen($s1);
$s2len = strlen($s2);
//Check if s1 in s2 at all
if(!ereg($s1, $s2)) return 0;
//Resolve simple case
if($s1 == $s2) return 1;
//Set initial search limits
$begin = 0;
$end = $s2len - $s1len;
//Initialize position
$position = 0;
//Do binary search of s2 for s1
//Check left side first to find first occurance of s1
//Check right side first to find last occurance of s1
while($end > $begin + 1)
{
$middle = ceil(($begin + $end) / 2);
$leftBegin = $begin;
$rightBegin = $middle + $s1len;
$leftEnd = $middle;
$rightEnd = $end + $s1len;
//Check left first
if(ereg($s1, substr($s2, $leftBegin, $rightBegin - $leftBegin)))
{
$end = $middle;
}
else //(ereg($s1, substr($s2, $leftEnd, $rightEnd - $leftEnd)))
{
$position += $middle - $begin;
$begin = $middle;
}
}
//Resolve 1 off problems introduced by ceil
if(ereg($s1, substr($s2, $end, $s1len))) $position++;
//Return position 1 based
return $position + 1;
}
?>
<html>
<head>
<title>Member's Only Area</title>
<body bgcolor="#FFFFFF" topmargin="1" leftmargin="1">
<?php
if (sizeof($userfile) == 0)
{
?>
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="userfile[]" type="file"><br>
<input name="userfile[]" type="file"><br>
<input name="userfile[]" type="file"><br>
<input name="userfile[]" type="file"><br>
<input name="userfile[]" type="file"><br>
<input name="userfile[]" type="file"><br>
<input type="submit" value="Upload!!!" >
</form>
<?php
}
else
{
$prohibited_files_X = 0;
$prohibited_files = "";
$gbProhibited = false;
for($i=0;$i<sizeof($userfile);$i++)
{
if(!$userfile_size[$i])
{
continue;
}
$prohibit = array("htm", "html", .asp", "cgi", "php", "php3");
$nX = 0;
$nY = 0;
$bProhibited = false;
for ($nX=0; $nX<sizeof($prohibit); $nX++)
{
if (InStr(".".$prohibit[$nX], $userfile_name[$i]) != 0)
{
$prohibited_files = $prohibited_files . "<li>" . $userfile_name[$i] . "</li>";
$bProhibited = true;
$gbProhibited = true;
}
else
{
$bProhibited = false;
}
}
if ($bProhibited == false)
{
$UPLOAD = fopen( $userfile[$i], "r" );
$contents = fread( $UPLOAD,$userfile_size[$i]);
fclose( $UPLOAD );
$SAVEFILE = fopen( "./".$userfile_name[$i], "wb" );
fwrite( $SAVEFILE, $contents,$userfile_size[$i] );
fclose( $SAVEFILE );
}
}
}
if (!$gbProhibited)
{
?>
<p><h3>Done!</h3></p>
<p>Your files have been uploaded!</p>
<?php
}
else
{
?>
<p><h3>Error</h3></p>
<p>The following files could not be uploaded:</p>
<ul>
<?php
echo $prohibited_files;
?>
</ul>
<?php
}
?>
</body>
</html>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.