Solved

Setting File filters

Posted on 2004-08-12
6
152 Views
Last Modified: 2010-04-09
Hi
I have to upload files from a php/html site.
Is there ne way to set the file type filter in upload dialog to images only.
0
Comment
Question by:zsadal
6 Comments
 
LVL 2

Expert Comment

by:Joakim_
ID: 11782467
You can use either JavaScript or PHP to check what the file exstension is. But don't ask me how.
0
 
LVL 31

Accepted Solution

by:
seanpowell earned 25 total points
ID: 11782499
Hi zsadal,

You should be able to handle this with some basic javascript. Here's a good write up that explains the process and limitations:

Filtering (through a file type filter)
http://www.cs.tut.fi/~jkorpela/forms/file.html#filter

Thanks,
Sean
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11784281
simple php solution, it wont filter it client side but will check server side

$allowed_files = array("image/gif","image/pjpeg","image/jpeg","image/jpg","images/png");

if (!in_array($_FILES['file_upload_form_field_name']['type'],$allowed_files)) {
  echo "this file type is not allowed";
 }
0
 
LVL 3

Expert Comment

by:Boris Aranovich
ID: 11840484
Are you talking about specifying hard-coded filters into <input type="file"...> ?
I think it is not possible, not my standard/pure HTML at least...
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
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…

760 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

22 Experts available now in Live!

Get 1:1 Help Now