Search code examples
phpdownloadsavefiledialogfiledialog

php - file download box


I'm giving a user a link to download a csv file ...just using

Click <a href="report.csv">here</a> to download your file.

This text and link is being displayed in a small popup window - height 100 width 400.

If the user clicks "save" - then no problem then the file is saved to wherever they choose

If though they choose "open" the csv file is then displayed in the small popup window. Which isn;t what I want - I'd prefer excel to open and display the file in excel, or even disabling the "open" button may be a possible option.

Any ideas how I can achieve either?

Thanks,


Solution

  • I assume that you are opening that popup box using some javascript .. so I'd suggest to dont show/open your tiny "download" popup box and instead show this link on a webpage. So when somebody clicks on the link force the browser to download the file and if they wish to open it they can and probably get a view which is as wide as of browswer's windows size.

    // just for example, to force download of a zip file, send the headers as

    // Set headers
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=$file");
    header("Content-Type: application/zip");
    header("Content-Transfer-Encoding: binary");