
 Horghidan Diana - 2012-01-05 13:28:42 - 
In reply to message 1 from edward sinagaHello!
This is something I have done:
function remove_bad_characters($text){
	$first	= array("\\", "/", ":", ";", "~", "<br>", "(", ")", "\"", "#", "*", "$", "@", "%", "[", "]", "{", "}", "<", ">", "`", "'", ",", " ");
	$last	= array("_", "_", "_", "_", "_", "_", "", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "", "_", "_");
	$text_rewrite = str_replace($first, $last, $text);
	return $text_rewrite;
}
if ( !is_dir($path)) {
    mkdir($path,0777,true);
}
if ( is_dir($path)) {
    chmod($path,0777);
    if(is_array($_FILES) && sizeof($_FILES) > 0){
          $filename= $_FILES['file_name']['name'];
	  $filename	= remove_bad_characters($filename);
	  if (@move_uploaded_file($_FILES['file_name']['tmp_name'], $path.$filename)){
                 //do something
         }else{
           switch ($_FILES['file_name']['error']){
		case 1:
			print '<p> The file is bigger than this PHP installation allows</p>';
			break;
		case 2:
			print '<p> The file is bigger than this form allows</p>';
			break;
		case 3:
			print '<p> Only part of the file was uploaded</p>';
			break;
		case 4:
			print '<p> No file was uploaded</p>';
			break;
		}
         }
  }else{
	print '<p> Invalid file</p>';
	break;
	}
  }
}
//$path - is the path where to upload the file;if the folders does not exist then are created
Sorry about the previous messages, but I am used to use tab to arrange the code.
Best regards