Viewed   46 times

I am trying to make an online kickstart config file creator. After the file is created on the server how do I get the download dialog to pop up so the user can download it?

 Answers

5

Content-Disposition header..

// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');

http://au2.php.net/manual/en/function.header.php

Saturday, December 3, 2022
3

Before you echo the data:

header('Content-Disposition: attachment; filename=save_as_name.jpg');

Then

echo file_get_contents("http://...");
Thursday, August 11, 2022
 
enapupe
 
4

if you are using html5 you can use download option

<a href="url_to_your_file.mp3" download>Download the mp3</a>

otherwise, you can use javascript

function saveAs(url) {    
  var filename = url.substring(url.lastIndexOf("/") + 1).split("?")[0];
  var xhr = new XMLHttpRequest();
  xhr.responseType = 'blob';
  xhr.onload = function() {
    var a = document.createElement('a');
    a.href = window.URL.createObjectURL(xhr.response);
    a.download = filename; 
    a.style.display = 'none';
    document.body.appendChild(a);
    a.click();
    delete a;
  };
  xhr.open('GET', url);
  xhr.send();
}

Call it from your link

<a href="javascript:" onclick="saveAs(url_to_your_file.mp3)">Download the mp3</a>
Tuesday, September 13, 2022
 
jeeka
 
5

EF BB BF is the UTF-8 encoding Byte Order Mark (BOM). I suspect there is some configuration option to turn off the BOM.

Edit: File editors should allow you to turn off the BOM when saving an file in relevant character encodings (e.g. UTF-8).

Thursday, September 8, 2022
 
16

The default actions are determined via the file MimeTypes.rdf, so this file is the one that you should modify once to suite your preferences, then copy to new installations.

Here is an extract from the documentation :

Attributes

General

  • RDF:about - identifier
  • NC:description - the name of the file type that will be displayed on the download prompt

Choosing what to handle

  • NC:fileExtension - file extensions to handle (note that content downloaded from the Internet will go by MIME type, not by file extension)
  • NC:value - MIME type to handle

Choose how to handle it (absence of the following options means "download to disk")

  • NC:path - path of the application to use to open this file
  • NC:useSystemDefault - true (use the system default for this MIME type) or false (define a different action)
  • NC:saveToDisk - true (default action is "download to disk") or false (don't download by default)

Additional options

  • NC:alwaysAsk - true (always ask which action to perform) or false (don't ask which action to perform)
  • NC:editable - true (entry can be modified with user interface) or false (entry is locked)
  • NC:prettyName - the short (display) name of the application

The file should be placed in the Profile folder that is suitable for the operating system and distribution and Firefox version (or fork) that you are using.

The dialog itself will appear with the choices as determined by these settings, or you can set it to automatically execute.


Please note that if you use the same profile on all computers, then Firefox Sync is also a solution.

Thursday, November 3, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :