我怎样才能使用php下载图像文件

I am try to download image file using php and i search on google and found some code but when i tryed out it's not working form plz some should help me out.

index.php

<?php
    // Array containing sample image file names
    $images = array("img5.jpg", "img2.jpg");

    // Loop through array to create image gallery
    foreach($images as $image){
        echo '<div class="d_c">';
            echo '<img src="' . $image . '" width="200" alt="' .  pathinfo($image, PATHINFO_FILENAME) .'">';
            echo '<p><a href="download.php?file=' . urlencode($image) . '">Download</a></p>';
        echo '</div>';
    }
    ?>

download.php

<?php
if(isset($_REQUEST["file"])){
    // Get parameters
    $file = urldecode($_REQUEST["file"]); // Decode URL-encoded string
    $filepath = "forum";

    // Process download
    if(file_exists($filepath)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($filepath));
        flush(); // Flush system output buffer
        readfile($filepath);
        exit;
    }
}
?>