Authenticity of uploaded pdf files

前端 未结 1 1649
时光取名叫无心
时光取名叫无心 2021-01-25 04:42

My server must only accept pdf files. I am using php to upload files. Currently, I am checking if the file starts with %PDF to ensure the uploaded file really is a pdf file. Are

相关标签:
1条回答
  • 2021-01-25 05:15

    You can use the PECL FileInfo extension to detect the MIME type. (I suspect however, that internally, it just does the same thing you're already doing.) Alternatively, you might use FPDI to see if you can successfully read the file. With PDF files though, I think embedded malware is a bigger concern than misnamed executables. Any time you're accepting uploads from users, it's probably a good idea to run the file through ClamAV or similar.

    0 讨论(0)
提交回复
热议问题