0

I have an file file.magicExt which is just a text file (utf-8), e.g.:

hello

I have an index.php:

<?php

echo '<a href="file.magicExt">file</a>';

What I would like is to show "open with" dialog when user click on "file" link.

Instead the browser (Firefox, Chrome) shows the file content.

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
PolGraphic
  • 3,233
  • 11
  • 51
  • 108

1 Answers1

0

I got it done with such file.php:

<?php

// We'll be outputting a .magicExt
header('Content-Type: application/magicExt');

// It will be called downloaded.magicExt
header('Content-Disposition: attachment; filename="downloaded.magicExt"');

// The .magicExt source is in original.magicExt
readfile('original.magicExt');

Based on PHP header() function

and that index.php:

echo '<a href="file.php">file</a>';
Barmar
  • 741,623
  • 53
  • 500
  • 612
PolGraphic
  • 3,233
  • 11
  • 51
  • 108