Category Archives: PHP

PHP Function To Quickly Implode Array Keys Into A String

In PHP there is a great function for converting a PHP Array into a string (and visa versa) using the function implode() as well as the array_keys() function to fetch the keys of the array. Combining these two functions, we can easily convert the keys of an array into a string. Note that as this [...]

PHP Function To Get File Mime Type

Whenever you need to determine the mime-type of a file you should generally look at the file extension. Below is a pretty straight forward function that will return the mime-type of a file based on its file extension. Note! this is not a guaranteed way to determine the mime-type since people can easily fake the [...]

Use PHP Headers to Force File Download

In apache, the file type will usually determine how the file is handled when viewing a website in our browser. For example, images, css, javascript, php, html (and other types) files are executed and displayed within the browser whereas PDF, ZIP, EXE and other unknown file types will be downloaded by the browser. Usually this [...]

Fastest way to format file size into kilobytes, megabytes and gigabytes

In this short post, you will find a PHP function that has got to be the quickest way to convert bytes into an easier to read format of kilobytes, megabytes, gigabytes and petabytes. The PHP filesize convert function takes the number (as bytes) passed to it and will convert it into an easier to read [...]