Sign in to follow this  
SteveDeFacto

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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 javascript. Try Googling it, as these things have usually been done a thousand times before.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Quote:
Original post by Erik Rufelt
Did you try something like this: http://javascript.internet.com/forms/upload-filter.html?
It was the first result for 'javascript upload file', seems to be doing exactly what you want.


Did you actually try it? The script only checks the file name after it is submitted, I already know how to do that...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this