[web] Input type="file" accept does not work so now what?

Started by
8 comments, last by JackOfAllTrades 14 years, 2 months ago
The accept attribute is not supported on any browsers for some reason... What can I do to create the same effect? I know it can be done because their are sites out there that do it. Here is a link if you don't know what I'm talking about.
Advertisement
You need ASPUPload for Classic asp file uploads..


http://aspupload.com/manual_simple.html
Quote:Original post by ROBERTREAD1
You need ASPUPload for Classic asp file uploads..


http://aspupload.com/manual_simple.html


My server does not support asp, it supports php and a license for that software is more then $200... I'm pretty sure there is a free way to do it and if not then I would rather use an input and upload the file with PHP.
As the site you linked to says: Tip: Avoid using this attribute. File uploads should be validated on the server. You can inspect the file-name in your PHP script to only accept a certain file-type. It should be fairly easy to add that functionality to your script, and if you need any help adding it just post your current code.

EDIT: Perhaps you want it client-side, didn't quite see that. Not sure how to do it, but might be possible with &#106avascript. Try Googling it, as these things have usually been done a thousand times before.
Quote:Original post by Erik Rufelt
As the site you linked to says: Tip: Avoid using this attribute. File uploads should be validated on the server. You can inspect the file-name in your PHP script to only accept a certain file-type. It should be fairly easy to add that functionality to your script, and if you need any help adding it just post your current code.


I am sure it is easy to do that but thats not as convenient for the user. If no one has any ideas on how to make the file browser display only files of a specified type then I will have to do that but I'm pretty sure there must be some way to do this...
Did you try something like this: http://&#106avascript.internet.com/forms/upload-filter.html</a>?<br>It was the first result for '&#106avascript upload file', seems to be doing exactly what you want.
Quote:Original post by Erik Rufelt
Did you try something like this: http://&#106avascript.internet.com/forms/upload-filter.html?
It was the first result for '&#106avascript upload file', seems to be doing exactly what you want.<!--QUOTE--></td></tr></table></BLOCKQUOTE><!--/QUOTE--><!--ENDQUOTE--><br><br>Did you actually try it? The script &#111;nly checks the file name after it is submitted, I already know how to do that...
Yes, and it doesn't send the file to the server unless the file-type is acceptable.

As for actually modifying the file selection dialog to only show files with a certain file-type, which in Windows means you can select something other than 'All Files' in the filter menu, I've never seen it. You say there are sites that do it, can you link to one?
Inspecting how that site does it could show a solution, as all client-side code will be available to you.

I agree that such a feature should be available, and I don't know why the accept attribute isn't implemented as it seems very easily done, but apparently it isn't. I tried Facebook photo upload for example, and it shows all files, and I don't see why they would do that if it was possible to change.
I also don't see how it really matters, unless it makes it slightly harder for people to find their photos in the dialog, but that seems quite far fetched.

You can make a custom file selection with ActiveX or as a java-applet (Facebook has this if you choose the Java uploader), and not use the standard file selection dialog, if you feel it's worth it to only display image files. Whether it will work will obviously depend on the user's browser and security settings.

It might be possible from a java-applet to display a standard java file selection dialog with a modified filter. I would look through the appropriate java documentation if that's an acceptable solution.
I've used SWFUpload to great effect. It's a flash program that allows you to do file uploads. You can do a lot of client-side verification as well as display progress as the file uploads, multiple uploads, etc.

It's open source, too, which is a bonus. The only downside is that it requires flash, of course.
Quote:Original post by Erik Rufelt
Yes, and it doesn't send the file to the server unless the file-type is acceptable.

As for actually modifying the file selection dialog to only show files with a certain file-type, which in Windows means you can select something other than 'All Files' in the filter menu, I've never seen it. You say there are sites that do it, can you link to one?
Inspecting how that site does it could show a solution, as all client-side code will be available to you.

I agree that such a feature should be available, and I don't know why the accept attribute isn't implemented as it seems very easily done, but apparently it isn't. I tried Facebook photo upload for example, and it shows all files, and I don't see why they would do that if it was possible to change.
I also don't see how it really matters, unless it makes it slightly harder for people to find their photos in the dialog, but that seems quite far fetched.

You can make a custom file selection with ActiveX or as a java-applet (Facebook has this if you choose the Java uploader), and not use the standard file selection dialog, if you feel it's worth it to only display image files. Whether it will work will obviously depend on the user's browser and security settings.

It might be possible from a java-applet to display a standard java file selection dialog with a modified filter. I would look through the appropriate java documentation if that's an acceptable solution.


This site does it

It seems to be using something similar to what Codeka suggested, I will probably use SWFUpload since it appears to be the best option though I'll never understand why browsers and general web development are so badly constructed.

I believe that any half decent programmer could build a superior implementation using sockets, SDL and python. This will probably never happen because we are still supporting legacy code thats over 20 years old and I know it will probably be supported for at least the rest of my life time and probably even for my children's children... sad thought...

This topic is closed to new replies.

Advertisement