Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
11-09-2011, 01:25 PM #1
- Join Date
- Oct 2011
- Thanked 0 Times in 0 Posts
Only offer specific uploadable file extensions in browse window
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, 01:47 PM #2
- Join Date
- Oct 2008
- Some say it's everything.
- Thanked 397 Times in 390 Posts
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 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):
file_types : "*.jpg; *.gif", file_types_description : "Image Files (JPG, GIF)",file_upload_limit : "0", }); }; </script>
The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
See Mediocrity in its Infancy
It's usually a good idea to start out with this at the VERY TOP of your CSS:
Seek and you shall find... basically: validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting