Solved

Javascript > Filter upload dialog

Posted on 2004-08-18
4
540 Views
Last Modified: 2006-11-17
How can i filter an upload dialog (using Browse control) to only dispay images? (GIF, PNG, JPG, JPEG, BMP)

Thanks
0
Comment
Question by:shaun341
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Squew01
ID: 11856108
W3C (web standard) defines the 'accept' argument to use like this:
<input type="file" accept="image/gif">
but unfortunatly this seems to work only in some version of netscape!!!!!
Sorry...

A good solution would be to use a server side script based on mime type of the uploaded file.
This is quite easy to do with PHP. Ask me for some help if you wanna...

/squew/
0
 
LVL 1

Author Comment

by:shaun341
ID: 11937431
Thanks for your reply, its not really an option in javascript it appears then.

How can i do it in PHP?
0
 
LVL 3

Accepted Solution

by:
Squew01 earned 50 total points
ID: 11940523
You can verify the kind of file using the mime-type. This info is givent by the browser to the web server.

When you upload a file with PHP, the browser gives infos about the uploaded file. Those info are automaticly stored into variables.
Ex. if you store the uploaded file in the $file var, $file_type will store the mime type of the file. (more info here: http://www.zend.com/manual/features.file-upload.php)

So, you just have to check the mime-type of the file, like this:

if(($file_type!="image/x-png")&&($file_type!="image/pjpeg")&&($file_type!="image/gif")&&($file_type!="image/bmp")&&($file_type!="text/xml"))
{
//file is not an image
}
else
{
//file is an image
}

Here is a list of existing mime-type :

image/gif
image/jpeg
image/pjpeg
image/tiff
image/x-png
image/x-xbitmap
image/bmp
image/x-jg
image/x-emf
image/x-wmf

Hopes this help and sorry for my english which is not as good as I want.

/squew/
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now