0

Is there any way to limit the type of file that can be uploaded using an HTML form via PHP? For example, I want to limit uploads to only .pdf files.

1
  • server-side limit or client-side limit? Commented Aug 15, 2011 at 21:52

2 Answers 2

2

Server side

Yes use superglobal $_FILES. look at this documentation page : PHP.net

It will get through basics, and then just look for file type, which is what you need to check with.

Client side

There are many ways to do this, but you can achieve this simply :

if((document.form1.upload.value.lastIndexOf(".jpg")==-1) {
   alert("Please upload only .jpg extention file");
   return false;
}
Sign up to request clarification or add additional context in comments.

1 Comment

there is also a type part to the $_FILES array which makes things much muuuuch easier ^_^
1

Yes. just look in the $_FILES array and read the file type.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.