Jump to content

Recommended Posts

hi.
i dont kno much abt headers, but sum1 gave me a small script to let me make any file download, even html or jpg's, that would normally just open in the browser...

the script goes something lyk this...

[code]
<?php

$file=$_GET['file'];
$filename=$_GET['filename'];


if(file_exists("$file")) {
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=$filename");
@readfile("$file");
}
exit;

?>
[/code]

...where "www.haha.com/?file=<X>&filename=<Z>" is the filename of the download...


the problem i am having, is that wen i use the script, the browser nev r knows how large the file is, and is unable to produce an ETA because of this.

i was wondering how it could b edited to enable this, or a new script that can do the same job.

thanx
Link to comment
https://forums.phpfreaks.com/topic/14106-force-download-with-headers/
Share on other sites

When the file is local (on same server as the script) use filesize() as in:

header('Content-Length: ' . filesize($file));

If the $file is a full URL (on another server), then read this topic for another option:

http://www.phpfreaks.com/forums/index.php/topic,97105.msg389848.html#msg389848
Book recommendation:

HTTP Developer's Handbook (ISBN: 0672324547) by Chris Shiflett.

http://www.amazon.com/exec/obidos/tg/detail/-/0672324547/qid=1151417523/sr=2-1/ref=pd_bbs_b_2_1/103-9175248-9725442?v=glance&s=books

It does have a little PHP related example code, but it's mostly about the HTTP protocol itself.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.