Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirming Markdown Files

I'm working on a PHP web application which will accept Markdown files as a file input.

How should I make sure that Markdown and only Markdown files are being uploaded?

I think I should check more than the extension... maybe the mime type?

If so, what is that mime type?

like image 393
citruspi Avatar asked Mar 15 '26 05:03

citruspi


1 Answers

extension and mime type are same.

check UTF-8, you can block any binary files (image files, etc)

if ($markdown !== iconv("UTF-8", "UTF-8//IGNORE", $markdown)) {

if an user uploads a HTML or JavaScript file, it is not what you want, but it match the Markdown syntax. so PHP can't identify it.

like image 171
Zheng Kai Avatar answered Mar 16 '26 22:03

Zheng Kai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!