Re: implementing downloads with php?

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

 




On Apr 2, 2015, at 8:48 PM, Sean Greenslade wrote:

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.

This I already have in hand. I am working currently on a CMS system
that uses a file browser application I wrote so I can designate a dir to send and upload file to, to select a path for a new file or rename a file, a number of related uses. It will list a single directory or all the directories at and below it. Now I can add a method to download files. I also have a web base file editor for plain text files that has open, save, and save as. So the file browser works vaguely similar to an open, save and save as file navigator in the Mac and other systems, but is web site based and applies to the web site content and file structure.


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

Thank you for your time, attention and patience;
JK

--
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