Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Upload file extension check
Old 12-05-2008, 03:55 AM Upload file extension check
Novice Talker

Posts: 10
Trades: 0
Hi,
I am looking for function which will check whether the uploaded file is of an image file. I want people to upload only image file and not any other file. Is it poss? I am not looking for php code. Thanks in advance.

Last edited by computerguy; 12-05-2008 at 03:58 AM..
computerguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-05-2008, 04:14 AM Re: Upload file extension check
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I am not looking for php code
So what code ARE you looking for then?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-05-2008, 04:20 AM Re: Upload file extension check
Novice Talker

Posts: 10
Trades: 0
javascript code, I am having file upload in jsp and onclick on submit it shud have javascript function which should check for the file extension and then the form should be submitted.

Thanks
computerguy is offline
Reply With Quote
View Public Profile
 
Old 12-05-2008, 04:23 AM Re: Upload file extension check
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Can't be done.

javascript has NO access to the filing system on the client machine.

neither does Flash
client side VBScript (IE only) can under certain circumstances but the user has to allow it first.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-05-2008, 04:25 AM Re: Upload file extension check
Novice Talker

Posts: 10
Trades: 0
I came across this code in this forum ,

Code:
<script language="JavaScript">
    extArray = new Array(".jpg", ".png", ".bmp");
    function LimitAttach(form, fileList) {
        alert("1");
    allowSubmit = false;
    if (!fileList) return;
    while (fileList.indexOf("\\") != -1)
    fileList = fileList.slice(fileList.indexOf("\\") + 1);
    ext = fileList.slice(fileList.indexOf(".")).toLowerCase();
    for (var i = 0; i < extArray.length; i++) {
    if (extArray[i] == ext) { allowSubmit = true; break; }
    }
    if (allowSubmit) return true;
    else
    alert("Please only upload files that end in types:  "
    + (extArray.join("  ")) + "\nPlease select a new "
    + "file to upload and submit again.");
    return false;
    }
    //  End -->
</script>
I think it checks for the file extension and allow the person to submit. Well anyways, thankx for Ur help.
computerguy is offline
Reply With Quote
View Public Profile
 
Old 12-05-2008, 04:41 AM Re: Upload file extension check
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Can we have a link to the thread please?

Because if it works ok we can point others to it.

Personally, I never had much success with blocking file uploads client side, and of course javascript can be turned off so you still have to check server side anyway.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-05-2008, 04:46 AM Re: Upload file extension check
Novice Talker

Posts: 10
Trades: 0
If you could help me in that it will be great, But anyways herez the link

http://www.webmaster-talk.com/javasc...ion-check.html

Thanks
computerguy is offline
Reply With Quote
View Public Profile
 
Old 12-05-2008, 04:49 AM Re: Upload file extension check
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Cheers,

I'll give that a try out later in the day.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-05-2008, 04:51 AM Re: Upload file extension check
Novice Talker

Posts: 10
Trades: 0
Thanks a lot, if U can PM me it will be great. Will be waiting for Ur msg.

Thanks
computerguy is offline
Reply With Quote
View Public Profile
 
Old 12-06-2008, 12:42 PM Re: Upload file extension check
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Finally got to playing with this.

It certainly stops the form being submitted for file extensions that are not in the array, however do not rely on it to prevent possible malicious uploads. Always ensure that a server side check is also in place, as I said in post #6, javascript can be turned off and then there would be no checks in place.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-08-2008, 02:35 AM Re: Upload file extension check
Novice Talker

Posts: 10
Trades: 0
Thankx for the help man, Will research more on this,

tc
computerguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Upload file extension check
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31472 seconds with 12 queries