Download a file from server with specific name in PHP

Download-Confirm.php

<?php 
        $n = "hello.xlsx";
        header('Content-Disposition: attachment; filename=' .$n. ' '); 
        header('Content-Type: application/xlsx');
        ob_clean();
        $url = "somename.xlsx";
        read_file($url);
        exit;
    ?>

    <!DOCTYPE html>
    <span><a href='http://www.somthing.com/files/somename.xlsx' download>CLICK HERE</a></span>

I need to download http://www.something.com/files/somename.xlsx this file from this PHP file…I tried header('Content-Disposition: attachment; filename= ’ .HELLO.xlsx. ’ '); But it only downloads the current php file into HTML document with the given filename and filetype…When I open it…It shows not a valid xlsx file or invalid format…

and when I tried to download only using anchor tag with download attribute it cant change the name I given…It downloads original file from the server but the file is working…But the problem is, I need to change the Name of the file according to the database name…

Any possible solutions???

After you’ve used read_file to load the contents of the file, don’t you need to output it to the browser in order for your user to save it locally?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.