View Full Version : Only offer specific uploadable file extensions in browse window

11-09-2011, 02:25 PM
Hi guys,

I'm offering my users the option to upload jpg/png files and it works as it's supposed to. Some people are just to lazy to read though and still try to upload bmp/gif etc... My script prevents the files from being uploaded, but what I would love above all is only showing jpg/png files in the browse window. Is there any way to do this with PHP or do I have to look into another language?


11-09-2011, 02:47 PM
This is really a client-side thing (PHP can't help).

There is an attribute called "accept" that can be used on an input element for file selection that would (theoretically) do this by specified MIME type, but it isn't really supported by browsers. The next best thing is to implement something in flash for file uploads. You would then have control to filter the filetypes the user sees by default in their file selection window.

You can give SWFUpload (http://swfupload.org/) a shot for starters (it seems to be a popular choice). It has a flag called "file_types" that can be set (as well as a description caption for the file types you choose to allow):

<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({// File Upload Settings
file_size_limit : "8 MB", // 2MB
file_types : "*.jpg; *.gif",
file_types_description : "Image Files (JPG, GIF)",
file_upload_limit : "0",