We help IT Professionals succeed at work.

browser upload restrict file types

6,558 Views
Last Modified: 2013-12-24
user clicks on browser upload button, the explorer window appears.   is there any way I can only show certain file types in this window, jpg, png etc? , like what you see in Photoshop?
 
PS I know I can check via the cf file upload tag for file types and I do this, but I just  want to add another layer to this before the user get to this stage.

Thanks to any one that can help with this. :)    
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
i was expecting that answer to be honest, i was praying it was not going to be the case, o well back to the drawing board. thanks again hows.  

PS
accept=image/jpg etc  is what i am already doing that fine, i just wanted to add more to the system.
James RodgersWeb Applications Developer
CERTIFIED EXPERT

Commented:
i do it ujsing js to check that teh file ext is allowed
here is a regex sample - i get it from a table where we specify teh file extesions and mime types that we allow for uploading
var sValidExt=/.doc$|.gif$|.html$|.jpe$|.jpeg$|.jpg$|.mdb$|.mov$|.mp3$|.mpg$|.pdf$|.pjpeg$|.ppt$|.wav$|.xls$|.zip$/;

and teh test routine
if(frmUploadFile['fUploadEN'+x].value && !sValidExt.test(frmUploadFile['fUploadEN'+x].value)){
                  frmUploadFile['fUploadEN'+x].style.backgroundColor='red';
                  if(!strErr){
                        objFocus=frmUploadFile['fUploadEN'+x]
                  }
                  strErr+="Invalid file type detected! Items marked in red cannot be uploaded.\n";
            }

Author

Commented:
Jester_48, in a different way this sounds like what i am after, but do you know if javascript would be able to tell the difference between jpeg and pjepg image files as CF allow file types when uploading via FireFox  does not.
James RodgersWeb Applications Developer
CERTIFIED EXPERT

Commented:
no, its just an extention read not a mime type check and a pjpeg can have an extention of .jpg
the code is more for preventing people from uploading a file ending in a specific extention, like .exe etc. before it gets processed by teh cfm page, just an added validation

Author

Commented:
thanks, on another note can i check for a mime type in cf?
Web Applications Developer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
thanks Jester
James RodgersWeb Applications Developer
CERTIFIED EXPERT

Commented:
glad i could help

thanks for the points

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.