define('MUILTI_FILE_UPLOAD', '10'); //Up to 10 files can be uploaded simultaneously
define('MAX_SIZE_FILE_UPLOAD', '500000' ); //File size No more than 5MB
define('FILE_UPLOAD_DIR', 'd:/'); //Directory for uploaded files
//File names allowed to be uploaded
$array_extention_interdite = array( '.php' , '. php3' , '.php4' , '.exe' , '.msi' , '.htaccess' , '.gz' ); //Extension of uploaded file
//Public function to display information
function func_message($message='', $ok=''){
echo '';
if ($ok == true){
echo '' ;
}
if($ok == false){
echo '< ;td width="100"> ';
}
echo '
' .$message.' '.$message.'
';
}
//Process form submission
$action = (isset($_POST['action'])) ? $_POST['action'] :'' ;
$file = (isset($_POST['file'])) ? $_POST['file'] :'' ;
if($file != '') {
$file = $ file.'/';
}
$message_true = '';
$message_false = '';
switch($action){
case 'upload' :
chmod(FILE_UPLOAD_DIR,0777);
for($nb = 1 ; $nb <= MUILTI_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'] ;
}
//Modification of file name
$file_name_final = strtr($file_name_final, 'aaaaaa', 'AAAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeeiiiioooooouuuuyy');
$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 . $file . $file_name_final );
$message_true .= 'File has been uploaded: '.$_FILES['file_'.$nb]['name'] .'
';
}else{
$message_false .= 'File upload failed: '. $_FILES['file_'.$nb]['name'] .'
';
}
}else{
$message_false .= 'File size exceeds'.MAX_SIZE_FILE_UPLOAD/1000 . 'KB : " '.$_FILES['file_'.$nb]['tmp_name'].'"
';}
}
}//end for
break;
}
?>
Multiple file upload