XUpload - Block certain characters in file naming.

XUpload related questions

Moderator: admin

Message
Author
ap
Posts: 21
Joined: Jan 08, 2007 10:35 pm

Block certain characters in file naming.

#1 Postby ap » Jan 24, 2007 5:40 pm

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.

User avatar
PilgrimX182
Posts: 2182
Joined: Mar 22, 2006 1:39 pm
Location: UFO Lab
Contact:

#2 Postby PilgrimX182 » Jan 25, 2007 7:44 am

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

ap
Posts: 21
Joined: Jan 08, 2007 10:35 pm

#3 Postby ap » Feb 02, 2007 5:26 pm

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

User avatar
PilgrimX182
Posts: 2182
Joined: Mar 22, 2006 1:39 pm
Location: UFO Lab
Contact:

#4 Postby PilgrimX182 » Feb 05, 2007 7:02 am

Ok then :D

In xupload.js update checkExt() function to this:

Code: Select all

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.

ap
Posts: 21
Joined: Jan 08, 2007 10:35 pm

#5 Postby ap » Feb 09, 2007 7:41 pm

That seems to do the trick. Thanks


Return to “XUpload”

Who is online

Users browsing this forum: No registered users and 0 guests