/*
######################################
# $passwords is an array of usable passwords.
# Make one password for yourself, make others for
# trusted relatives to upload photos directly to your site
# set $path to your uploads directory.
# upload directory must have 777 permissions.
# $number_of_files = number of upload inputs.
# $max_size = max file size in bytes
# $allowed is an array of allowed file extensions.
# do not allow scripts like .php, .pl or .cgi to be uploaded
# if $overwrite = "no" then overwriting blocked
######################################
*/
$passwords = array( "your_password", "guest_password" );
$path = "uploads/";
$number_of_files = 10;
$max_size = 30000000;
$allowed = array( "jpeg", "jpg", "gif", "png", "avi" );
$overwrite = "no";
$body_bg = "fad888";
$table_bg = "slategray";
$th = "black";
$title = "DJ Mike's Multi File Uploader";
$self = "$_SERVER[PHP_SELF]";
######################################
session_start();
############## log out ###############
if ( $_POST[logout] )
{
$_SESSION[pass] = "";
$_SESSION = "";
session_destroy();
header("location:$self");
exit;
}
#####################################
############### or log in ##############
elseif ( in_array( "$_POST[pass]", $passwords ) )
{
$_SESSION[pass] = "$_POST[pass]";
header("location:$self");
exit;
}
#####################################
?>
echo "$title"; ?>
">
echo "$title"; ?>
#### hide upload form if not logged in
if ( !in_array( "$_SESSION[pass]", $passwords ) )
{
echo "Logged out
";
echo "";
exit;
}
else
{
echo "Logged In
";
}
?>
Upload directory
#### start upload ####
## do it only if files submitted
if ( $_FILES )
{
# start loop
echo "Attempting Upload...
";
for ( $x=0; $x<=$number_of_files-1; $x++ )
{
# do it only if file has original name
# prevents processing when nothing submitted
if ( isset($_FILES[file_name][name][$x]) )
{
# check for upload problems
####
if ( $_FILES[file_name][error][$x] > 0 )
{
echo "
The file could not be upoaded because ";
switch ( $_FILES[file_name][error][$x] )
{
case 1:
echo "the file is too big.";
break;
case 2:
echo "the file is too big.";
break;
case 3:
echo "the file was only partially uploaded.";
break;
case 4:
echo "no file was uploaded.";
break;
case 6:
echo "no temporary folder was available.";
break;
case 7:
echo "unable to write to disk.";
break;
case 8:
echo "file upload stopped";
break;
default:
echo "a system error occured.";
} # end of switch
echo "
";
exit;
}
#### end of if files > 0
#### if file uploaded, get extension
else {
$original_name = $_FILES[file_name][name][$x];
$original_name = trim($original_name);
$type = explode(".", $original_name);
$count = count($type);
$last = $count-1;
$type = "$type[$last]";
$type = strtolower($type);
# test extension type
if ( !in_array( $type, $allowed) )
{
echo "File type ($type) is not allowed
";
}
# then see if it is small enough
elseif ( $_FILES[file_name][size][$x] > $max_size )
{
echo "File is too big
";
}
# if no errors and small enough, sanititize name
else
{
# if no new name use original name
if ( $_POST[new_name][$x] == "" )
{
# snip extension
$original_name = str_replace( ".$type", "", $original_name);
# sanitize original name
$original_name = preg_replace("@[^\w\.]@", "_", $original_name);
# add extension and directory path to clean name
$file_name = "$path$original_name.$type";
}
# if new name submited, use it
else
{
# sanitize new name
$newname = $_POST[new_name][$x];
$newname = trim($newname);
$newname = preg_replace("@[^\w\.]@", "_", $newname);
# add extension and directory path to clean name
$file_name = "$path$newname.$type";
}
# prevent overwriting if $overwrite is "no"
if ( $overwrite == "no" && file_exists($file_name) )
{
echo "File $file_name already exists.
";
}
# move uploaded file to upload directory
# suppress PHP error message
elseif ( @move_uploaded_file($_FILES[file_name][tmp_name][$x], $file_name) )
{
echo "File uploaded to $file_name.
";
}
# if move fails, give your own error message.
else
{
echo "An error occured. File Not uploaded
";
}
}
echo "
";
}
} # end isset file name
}
echo "