Solved

Javascript > Filter upload dialog

Posted on 2004-08-18
4
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

626 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