| View previous topic :: View next topic |
| Author |
Message |
ap
Joined: 08 Jan 2007 Posts: 21
|
Posted: Jan 24, 2007 5:40 pm Post subject: Block certain characters in file naming. |
|
|
| Is there a way to program in the config file a way to alert a user if their file names contain any special chracters like @, #, %, etc. It would be nice to alert a user that they used a character not support in their file names. Like the way the script only allows certain extensions. Macintosh has a problem with certain chacters. |
|
| Back to top |
|
 |
PilgrimX182

Joined: 22 Mar 2006 Posts: 2106 Location: UFO Lab
|
Posted: Jan 25, 2007 7:44 am Post subject: |
|
|
There's filaname_mask option in config in Pro version. But it don't show alert, just don't save file and set status=unallowed filename in POST request.
You can validate filename when selecting file with JS. Just add another regexp in checkExt function in xupload.js |
|
| Back to top |
|
 |
ap
Joined: 08 Jan 2007 Posts: 21
|
Posted: Feb 02, 2007 5:26 pm Post subject: |
|
|
| Not sure I followed you on this. What do I need to add, and where under the .js script and under the config script. Thanks |
|
| Back to top |
|
 |
PilgrimX182

Joined: 22 Mar 2006 Posts: 2106 Location: UFO Lab
|
Posted: Feb 05, 2007 7:02 am Post subject: |
|
|
Ok then
In xupload.js update checkExt() function to this:
| Code: |
function checkExt(obj)
{
value = obj.value;
if(value=="")return true;
var re = new RegExp("^.+\.("+ext_allowed+")$","i");
if(!re.test(value))
{
alert("Extension not allowed for file: \"" + value + "\"\nOnly these extensions are allowed: "+ext_allowed.replace(/\|/g,',')+" \n\n");
return false;
}
var re = new RegExp("[\@\#\%]","i");
if(re.test(value))
{
alert("Selected filename contain bad characters!\n\n");
return false;
}
return true;
}
|
In this function we show error if filename contain '@','#','%'. You can add other 'bad' symbols to RegExp. |
|
| Back to top |
|
 |
ap
Joined: 08 Jan 2007 Posts: 21
|
Posted: Feb 09, 2007 7:41 pm Post subject: |
|
|
| That seems to do the trick. Thanks |
|
| Back to top |
|
 |
|