Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 27
    Just remember, depending on your file, that you might miss some text formats: application/xml (and similar like RSS), application/ecmascript, application/json, image/svg+xml, ... You'd have to whitelist those. Commented Apr 11, 2016 at 7:38
  • @Boldewyn wow, nice examples! So probably a better answer is just to accept any file that has only printable chars, but somehow also cope with utf-8 and similar encoding problems. Commented Apr 11, 2016 at 7:49
  • Yes, that's the gist of my answer below. Only problem is, that that solution has to look at the whole file... Commented Apr 11, 2016 at 8:19
  • 7
    @Boldewyn In principle, application/* types are not intended for human consumption, even when they may be text-based to facilitate development and debugging. That's why there is both a text/xml and an application/xml. So the question whether to consider them as text depends on the OP's needs. Commented Apr 11, 2016 at 8:46
  • 4
    Or cut -d/ -f1 Commented Apr 11, 2016 at 9:07