Re: implementing downloads with php?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 02, 2015 at 08:29:40PM -0700, Jeffry Killen wrote:
> No I wasn't intending to use ajax per-se. I was just using that as a
> parallel
> to illustrate using a print statement to actually send the file contents.
> Is it  necessary to call print or echo here?

OK, then we're on the same page here (no pun intended).

When running a PHP script that sets headers, the only requirement is
that you set the headers before _any_ content has been displayed.
Basically, that means that the very first characters of the PHP file
must be "<?php" and no echos or other content-generating commands are
run until after all headers are set. There's no requirement to call
echo, the headers are sent even if your page contains no content at all.

> I would print a directory listing of a directory containing downloadable
> files
> to the browser with php, where each file listing is wrapped in an anchor
> that has the href value set to a script with a query attached: something
> along the lines of  <a href="downloader.php?file=[file to download]">[file
> to download]</a>

Perfectly doable. Downloader.php simply needs to set the headers,
interpret the GET variable, and stream the file. Listing the directory
is a separate problem, and you'll surely find plenty of tutorials by
searching online.

> I am thinking of any file type: .pdf, .rtf, .swf, .doc, mpg, mpeg, mp3,
> binary, as well as plain text, whatever

Also easy. Set the Content-Type header to the file's corresponding MIME
type.

--Sean

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux