Setting File filters

Posted on 2004-08-12
Last Modified: 2010-04-09
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.
Question by:zsadal

Expert Comment

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

Accepted Solution

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)

LVL 27

Expert Comment

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";

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...

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change div area and length 1 34
Create animated movies for web page 18 84
Powershell script does not exit 4 26
..ignore the Question 1 7
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

840 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