php file upload, how to restrict file upload type

前端 未结 5 1180
小蘑菇
小蘑菇 2020-11-29 11:38

I have the following code to check if (resume and reference letter uploaded match desired type (pdf OR doc OR docx) and size (less than 400 kb)

//check file          


        
5条回答
  •  执笔经年
    2020-11-29 12:19

    To do that I usually using something like that:

    $filename = $_FILES['field_name']['name']; // Get the name of the file (including file extension).
    $ext = strtolower(substr($filename, strpos($filename,'.'), strlen($filename)-1)); //get the extention in lower case
    

    And than check if the file extension is accepted.

    Also be aware that that the user can simply change the extension for a dangerous file, so it is safer to check with the mime type

提交回复
热议问题