<?php
# Copyright © 2007 wimpel2
# wimpel2@thegreenknights.be.tc
# multi upload
define('NB_FILE_UPLOAD', '10'); // nombre de fichier a envoyer (aucune limite :) )
define('MAX_SIZE_FILE_UPLOAD', '500000000' ); //soit 50 Ko
define('FILE_UPLOAD_DIR', dirname($_SERVER['SCRIPT_FILENAME']).'/'); // direction des fichier a uploader
$array_extention_interdite = array( '.bmp' , '.dib' , '.JPG' , '.JPEG' , '.JPE' , '.JFIF' , '.GIF' , '.TIFF' , '.PNG' );
function func_message($message='', $ok='')
{
echo '<table width="100%" cellspacing="0" cellpadding="5">';
if($ok == true){ echo '<tr bgcolor="#99FF99" ><td width="100"> </td><td class="text_noir">'.$message.'</td></tr>' ;}
if($ok == false){ echo '<tr bgcolor="#FF99CC" ><td width="100"> </td><td class="text_noir">'.$message.'</td></tr>';}
echo '</table>';
}
$action = (isset($_POST['action'])) ? $_POST['action'] :'' ;
$dossier = (isset($_POST['dossier'])) ? $_POST['dossier'] :'' ;
if($dossier != '') {$dossier = $dossier.'/';}
$message_true = '';
$message_false = '';
switch($action)
{
case 'upload' :
chmod(FILE_UPLOAD_DIR,0777);
for($nb = 1 ; $nb <= NB_FILE_UPLOAD ; $nb ++ )
{
if( $_FILES['file_'.$nb]['size'] >= 10 )
{
if ($_FILES['file_'.$nb]['size'] <= MAX_SIZE_FILE_UPLOAD )
{
if ( !in_array( ereg_replace('^[[:alnum:]]([-_.]?[[:alnum:]])*\.' ,'.', $_FILES['file_'.$nb]['name'] ) , $array_extention_interdite) )
{
if($_POST['file_name_'.$nb] !=''){ $file_name_final = $_POST['file_name_'.$nb].$extension ;}
else { $file_name_final = $_FILES['file_'.$nb]['name'] ;}
$file_name_final = strtr($file_name_final, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$file_name_final = preg_replace('/([^.a-z0-1]+)/i', '_', $file_name_final );
$_FILES['file_'.$nb]['name'] = $file_name_final;
move_uploaded_file( $_FILES['file_'.$nb]['tmp_name'] , FILE_UPLOAD_DIR . $dossier . $file_name_final );
$message_true .= 'Foto is verzonden : '.$_FILES['file_'.$nb]['name'] .'<br>';
}
else{
$message_false .= 'Er is iets fout gedaan : '.$_FILES['file_'.$nb]['name'] .' <br>';
}
}
else{ $message_false .= 'Foto is te groot '.MAX_SIZE_FILE_UPLOAD/1000 . 'ko : " '.$_FILES['file_'.$nb]['tmp_name'].'" <br>';}
}
}//end for
break;
}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Multi - Upload</title>
<style>
.body{ SCROLLBAR-ARROW-COLOR: #ff9933;
SCROLLBAR-DARKSHADOW-COLOR: #000000;
SCROLLBAR-BASE-COLOR: #005b70;
background-color:#ffffff}
.border{background-color:#000000}
.box{background-color:#f8f8f9;}
.text_noir{ color:#000000;
font-family: Verdana, Arial, sans-serif;
font-size: 11px;
font-weight:bold}
input, select{ font-family: Verdana, Arial, sans-serif;
font-size: 11px;
background-color: #ffffff;
border-color:"#ffffff"}
</style>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<?php if (function_exists('ini_get')) {?><br>
<table width="600" border="0" cellspacing="1" cellpadding="0" align="center" class="border">
<tr>
<td>
<table width="100%" border="1" align="center" cellspacing="5" cellpadding="2" class="box">
<tr class="text_noir">
<td colspan="2" align="center">Uw mogelijkheden</td>
</tr>
<tr class="text_noir">
<td>file_uploads :</td>
<td>
<?php if (ini_get('file_uploads') ==1) { echo 'On'; } else { echo 'Off'; }?>
</td>
</tr>
<tr class="text_noir">
<td>upload_max_filesize :</td>
<td> <?php echo ini_get('upload_max_filesize'); ?> </td>
</tr>
<tr class="text_noir">
<td>post_max_size :</td>
<td> <?php echo ini_get('post_max_size'); ?> </td>
</tr>
<tr class="text_noir">
<td>upload_tmp_dir :</td>
<td> <?php echo ini_get('upload_tmp_dir'); ?></td>
</tr>
<tr class="text_noir">
<td>Extension interdites :</td>
<td> <?php for ($i=0; $i < sizeof($array_extention_interdite); $i++)
{ echo $array_extention_interdite[$i] .' | '; }
?></td>
</tr>
</table>
</td>
</tr>
</table><br>
<?php }?>
<br>
<form name="form" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF'] ; ?>">
<input type="hidden" name="action" value="upload">
<table border="0" cellspacing="1" cellpadding="0" align="center" class="border">
<tr>
<td>
<?php if($message_true != '') { func_message($message_true, true); }
if($message_false != ''){ func_message($message_false, false); }
?>
<table width="100%" border="0" cellspacing="5" cellpadding="2" align="center" class="box">
<?php
for($nb = 1 ; $nb <= NB_FILE_UPLOAD ; $nb ++ )
{
?>
<tr class="text_noir">
<td>Foto <?php echo $nb; ?></td> <td><input type="file" name="file_<?php echo $nb; ?>"></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" align="right" class="text_noir"><?php echo FILE_UPLOAD_DIR ;?>
<select name="dossier">
<option value=""></option>
<?php
$repertoire = opendir(FILE_UPLOAD_DIR);
while( $file = readdir($repertoire) )
{
$file = str_replace('.','',$file);
if( is_dir($file)) {
?>
<option value="<?php echo $file; ?>"> <?php echo $file; ?>/</option>
<?php
}
}
closedir($repertoire);
?>
</select>
</td>
<td colspan="2" align="right"><input type="submit" value=" Verzend <?php echo $nb-1; ?> Foto's "></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<br><br>
<div align="center" class="text_noir">Copyright © 2007 willem@3handel.be.tc</div>
<br>
</body>
</html>