View Single Post
Old 09-29-2007, 08:07 AM   #1 (permalink)
Sam Granger
The Acquainted
 
Join Date: Sep 2007
Posts: 126
Thanks: 4
Sam Granger is on a distinguished road
Default checking file extensions. How can I change this?

Code:
	function checkFileExtentions(form){
		if(check_file_extentions == false){ return false; }
		var re = /(\.php)|(\.sh)$/i;
		if(form['filename'].value != ""){
			if(form['filename'].value.match(re)){
				var string = form['filename'].value;
				var num_of_last_slash = string.lastIndexOf("\\");
				if(num_of_last_slash < 1){ num_of_last_slash = string.lastIndexOf("/"); }
				var file_name = string.slice(num_of_last_slash + 1, string.length);
				var file_extention = file_name.slice(file_name.indexOf(".")).toLowerCase(); 
				alert('Sorry, uploading a file with the extention "' + file_extention + '" is not allowed.');
				return true;
			}
		}
		return false;
	}
I have the following js code. At the moment, it warns me if I want to upload a php file. How can I make it warn me for all file extensions, with the exception of .jpg? :confused:
Sam Granger is offline  
Reply With Quote