NYCPHP Meetup

NYPHP.org

[nycphp-talk] Re:filesize & download

John Campbell jcampbell1 at gmail.com
Wed Feb 6 11:11:34 EST 2008


On Feb 6, 2008 2:29 AM, Aniesh joseph <anieshjoseph at gmail.com> wrote:
> I tried stat() function but it doesn't return the result. Anyway I got a
> function to calculate the size of the remote file and it works fine. The
> page link is below:
>
> http://textsnippets.com/posts/show/1214

I am impressed you wrote that, but you should use curl instead.  Just
set it to follow redirects and only download the headers.  There is no
reason to write a partial implementation of HTTP using
streams/sockets.

> But now some other issue at the time of audio download. I use the following
> headers in  the download page:
>
>
>  $mm_type="application/octet-stream";
>
>  header("Cache-Control: public, must-revalidate");
>  header("Pragma: hack");
>  header("Content-Type: " . $mm_type);
>  header("Content-Length: " .(string)(filesize($myFile)) );
>  header('Content-Disposition: attachment; filename="'.$filename.'"');
>  header("Content-Transfer-Encoding: binary\n");
>
>  readfile($myFile);

I don't think you need Content-Disposition or
Content-Transfer-Encoding headers since you are only sending one file
per request.  I am not sure why you have a cache-control header
either.

John C.



More information about the talk mailing list