KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Does PHP have a function that returns a file extension given a content type? I'm looking for something that works like: <?php function getFileExtension($contentType) { if ($contentType === 'image/png') { return '.png'; } elseif ($contentType === 'image/jpg') { return '.jpg'; } elseif ($contentType === 'application/zip') { return '.zip'; } else { return FALSE; } } The goal is to use a library function that has all content types handled. Based on the pattern above, I guess I could roll my own with something like this: <?php function getFileExtension($contentType) { $pieces = explode('/', $contentType); return '.' . array_pop($pieces); } ... but that seems janky. Anybody know of an already authored PHP solution? LMK. Thanks!
Tags (comma-separated)
Save Edits
Cancel