Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003

    php and http header question

    I'm making a script that will send http headers so the browser will download the file.

    my question is that for some file types the browser will choose to open the file and run it (.asf, .wmv etc) instead of downloading it.

    my question is that is there a way to make the browser download the file (with the save as popup dialog) everytime instead of running it as it downloads?

  2. #2
    Join Date
    Aug 2003
    I believe there is a one-liner using htaccess if you are on an apache server. I don't have the link handy, but I remember when I was first using htaccess there was a command that was a server-type that made a particular file be downloaded with the box-prompt instead of just downloading to the temp directory.

    Sorry I couldn't be more help.

  3. #3
    This should work:
    header("Content-Type: application/octet-stream");
    header("Content-Length: ".filesize($file));
    header("Content-Disposition: attachment; filename=" .basename($file));
    while (!feof($f)) $data.=fread($f,64000);
    print $data;

  4. #4
    Join Date
    Oct 2003
    yeah i found it i can do it with this
    header('Content-Type: application/asf');
    header('Content-Disposition: attachment; filename=$file');
    header('Content-Description: rar');
    header('Connection: Close');

    but this makes the server read the file and then send it to the user. quite banwidth and memory intensive since most of the files won't be on my server. is there anyway to use http header to make the user download from a remote location?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts