citruspi
citruspi

Reputation: 6891

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?

Upvotes: 3

Views: 221

Answers (1)

Zheng Kai
Zheng Kai

Reputation: 3635

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.

Upvotes: 1

Related Questions