0

So, as most of you may know, when you put a link to a file on a webpage, you must right-click the link and click "save link as" to download the file. I wanted to know if there is a way to just be able to click the link and automatically download the file.

saoud
  • 49
  • 1
  • 2
  • 9

1 Answers1

2

There is a way, using header() calls to specify Content-Disposition.

For example, I have an image download script that looks like this:

header("Content-Type: $mime");
header("Content-Disposition: attachment; filename=\"foobar.baz\"");
readfile($filename);

You need to find out what the MIME type of the file is (and set it using Content-Type: $mime, tell the browser this file is an attachment using the Content-Disposition header, and then output the file with readfile().

This tutorial has some more information on the matter.

Bojangles
  • 99,427
  • 50
  • 170
  • 208
  • thank you so much guys and sorry, im new to stack overflow, wasnt really sure where to start. – saoud Dec 21 '11 at 06:41