QUICK QUESTION
Moderator: General Moderators
-
sirstrumalot
- Forum Commoner
- Posts: 27
- Joined: Mon May 18, 2009 10:26 pm
QUICK QUESTION
Can I set something in JS or an other language in a form so that when someone clicks "Browse" to upload a file that the file extension is already set in the upload window for a particular type of file, like a .jpeg? This way they can't upload, for example, a csv because they can't see it.
Re: QUICK QUESTION
I think you'll probably need some sort of Java applet for this, never seen it done in JS before
Re: QUICK QUESTION
Can't be done in JavaScript (or HTML or anything else of that nature).
Re: QUICK QUESTION
I don't see how it can be done in HTML? Or even JavaScript easily...
-
sirstrumalot
- Forum Commoner
- Posts: 27
- Joined: Mon May 18, 2009 10:26 pm
Re: QUICK QUESTION
I was talking about this:
But this doesn't seem to work with my forms. I'm assuming it's either because i'm writing in PHP or because i'm using XHTML. I'm not certain why it's not working, but the file types like "text/csv" or "image/jpeg" are standard MIME types for the file type of input. This way the extension shows in the browse box. But it's not working. Ideas?
Code: Select all
<input type="file" accept="image/jpeg">Re: QUICK QUESTION
input's accept attribute is official - it's defined in all the HTML standards - but there aren't any browsers that implement it. That's why it isn't working.
MIME types, by the way, have nothing to do with the extension and more about the data contained in the file. But since you're really trying to get a type of file and not just any file with a specific extension, that wouldn't be a problem.
So a clarification to my earlier post:
You can specify the type(s) of file accepted but the <input>, but it doesn't work. The W3C guys even recommend against using it, stating (correctly) that file validation should be done on the server, not the client.
MIME types, by the way, have nothing to do with the extension and more about the data contained in the file. But since you're really trying to get a type of file and not just any file with a specific extension, that wouldn't be a problem.
So a clarification to my earlier post:
You can specify the type(s) of file accepted but the <input>, but it doesn't work. The W3C guys even recommend against using it, stating (correctly) that file validation should be done on the server, not the client.
-
sirstrumalot
- Forum Commoner
- Posts: 27
- Joined: Mon May 18, 2009 10:26 pm
Re: QUICK QUESTION
That's what I was looking for. I appreciate it!
btw, would you recommend a method of server side validation? Currently i'm using javascript to validate the file extension onchange of the input, but that doesn't stop them, it only alerts them. What methods are out there to ensure it is what I want them to upload?
Thanks again!
btw, would you recommend a method of server side validation? Currently i'm using javascript to validate the file extension onchange of the input, but that doesn't stop them, it only alerts them. What methods are out there to ensure it is what I want them to upload?
Thanks again!
Re: QUICK QUESTION
Don't use the file extension. It means very little. Don't use the MIME type either. Both of them are content sumbitted by the user and therefore cannot be trusted.
If you want to be sure something is a JPEG image, use getimagesize(). One of the returned values is the image type.
If you want to be sure something is a JPEG image, use getimagesize(). One of the returned values is the image type.
-
sirstrumalot
- Forum Commoner
- Posts: 27
- Joined: Mon May 18, 2009 10:26 pm
Re: QUICK QUESTION
Very good recommendation! They can always change the extension. However, i'm curious how to do this if it's a csv.... thoughts?