Hey Dan,
You need to send the information about the file in the headers. I have a site
that
allows for downloads and I use some code that looks like this:
<?php
$item_title = htmlentities($_GET['item_title']);
$download_file = htmlentities($_GET['download_file']);
$file_type = htmlentities($_GET['file_type']);
$download_title = str_replace(' ','_',$item_title);
$mime_type = mime_content_type($download_file);
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
header("Cache-Control: public");
header("Content-Description: File Transfer");
$real_file_size = filesize($download_file);
header("Content-Length: $real_file_size");
header("Content-type: $mime_type");
header("Content-Disposition: attachment; filename=\"$download_title.
$file_type\"");
header("Content-Transfer-Encoding: binary");
readfile($download_file);
?>
I have the database tell me what the item title is, because I store it as a
timestamp so I
have no duplicates. It also tells me what the filetype is so I know what file
type to
place in the headers. I think all you need is the header() sections and fill in
the
variables with your specifics.
Hope this helps!
On Friday, May 24, 2013 02:15:37 PM Dan Egli wrote:
> *Hey folks. I have what I think is a simple question, but I've looked for
> examples (admittedly briefly) and I can't find any. *
>
> * *
>
> *I am designing a web site in PHP. One of the things that the site will
> allow is to download various files. The files are stored in a postgres
> table and extracted as needed (that's how the guy I'm designing it for
> wants it. I am sure it would be easier to simply store filenames & paths in
> the DB but he doesn't want that). The problem I have is that I'm not sure
> how to inform the web browser that the filename to save isn't the filename
> of the php file. I.e. if the download URL is
> get_file.php?filename=example.zip then how do I tell the web browser that
> the file's default name is example.zip and not get_file.php?*
>
> * *
>
> *Thanks!*
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/