开发者

Limiting file types/extensions when uploading files in an HTML form

开发者 https://www.devze.com 2023-03-28 19:59 出处:网络
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 .pd开发者_StackOverflow中文版f files.Server side

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 .pd开发者_StackOverflow中文版f files.


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;
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消