Home Simple File Download Select Menu

    Simple File Download Select Menu


    This code is an example of how you might include multiple files of a particular type available in a select menu. On selecting the option the relevant zip file will be downloaded. Because we use it specifically for zip files, the browser handles the download without an intermediary file. If you were to use it for a page navigation menu (in which case you wouldn’t be using the glob() function as we’ve done), or you had a directory with a deep hierarchy (in which case you might use something like our last function), only minor modifications would need to be made.

    Because our use meant scanning a large directory, we cache the resulting select menu using Simple Cache.

    The Result

    The result is a standard select menu. Selecting a file will force the download (assuming you’re listing zip files).

    Simple File Download Select Menu

    PHP Code


    • Other variations of this code are forthcoming. This includes a WordPress shortcode.
    • Information on glob() function from the PHP Manual .
    • We’ve got another cool function that we’ll share soon that uses glob() to read all images from a directory and render then on a page in responsive rows (an easy way to create a quick image gallery).
    • To exclude specific files form being listed in the dropdown menu, include their name (with extension) in the $exclude array.

    Short URL for this post: http://shor.tt/1XHs