Page 1 of 1
Headers for download
Posted: Mon Aug 25, 2003 10:59 am
by Emerald
I have a download script that inludes this page to get the url of the file to download. The file is .wma (Windows Media) format.
My problem with this is that when it brings up the popup download box, it says: You have chosen to download a file.
10.wma from
http://www.mywebsite.com.
When I choose save, it downloads a "blank" file in like 2 sec. (It's a 4Mb file).
What seems to be the problem???
CODE:
<?
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".basename($url).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($url));
?>
($url is the whole web url of the file)
Posted: Mon Aug 25, 2003 11:23 am
by volka
after the
header("Content-Length: ".filesize($url));you send the content via
readfile?
Posted: Mon Aug 25, 2003 12:04 pm
by Emerald
I have used :
readfile("$url");
in the code also.
What it does is show the progess bar loading in the browser for a long time before the download box will appear. Then when it does, & i save it does the same thing. Downloads a blank file in 2 sec.
It didn't make a difference in the script.
Does it make a difference if I'm referring to a URL versus a server location like d:/website/www/folder/file.wma?
Posted: Mon Aug 25, 2003 6:27 pm
by volka
do you mean $url looks like 'http://some-serv.er/a/file.wma' ?
Posted: Mon Aug 25, 2003 6:42 pm
by Emerald
Yes.
It picks up file.wma when the download box appears(after a long wait) & then when saving it, it basically saves nothing.
Posted: Mon Aug 25, 2003 6:48 pm
by volka
then at least filesize() will fail
Posted: Mon Aug 25, 2003 7:39 pm
by Emerald
I have made a url entry in the database as a local file on server.
My local path is /usr/sites/blahblah.
I noticed the download box popup quick, but still ain't downloading nothing.
How can I tell it to get the file on the machine.
Posted: Mon Aug 25, 2003 11:00 pm
by volka
you script now looks like
Code: Select all
<?php
// $url is a local path like /usr/sites/dlfile1
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".basename($url).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($url));
readfile($url);
?>
?
You might check those values
Code: Select all
<pre><?php
echo("Pragma: public"), "\n";
echo("Expires: 0"), "\n";
echo("Cache-Control: must-revalidate, post-check=0, pre-check=0"), "\n";
echo("Content-Type: application/octet-stream"), "\n";
echo("Content-Disposition: attachment; filename=".basename($url).";"), "\n";
echo("Content-Transfer-Encoding: binary"), "\n";
echo("Content-Length: ".filesize($url)), "\n";
?></pre>
perhaps they're not what you suppose them to be.
Posted: Tue Aug 26, 2003 9:50 am
by Emerald
It reads filename="aSong.wma", but it don't display anything for the Content-Length.
Thanks for trying to help me out.
Posted: Tue Aug 26, 2003 10:45 am
by volka
sounds to me like the path in $url is wrong.
Code: Select all
<pre><?php
if (!is_file($url))
echo "'$url' is not a valid file/path";
echo("Pragma: public"), "\n";
echo("Expires: 0"), "\n";
echo("Cache-Control: must-revalidate, post-check=0, pre-check=0"), "\n";
echo("Content-Type: application/octet-stream"), "\n";
echo("Content-Disposition: attachment; filename=".basename($url).";"), "\n";
echo("Content-Transfer-Encoding: binary"), "\n";
echo("Content-Length: ".filesize($url)), "\n";
?></pre>
Posted: Tue Aug 26, 2003 11:46 am
by Emerald
The page originates from dl.php?id=3
which brings up the code/message:
'
http://goldenstreetmusic.sitestream.com/Beethoven.wma' is not a valid file/path
Pragma: public
Expires: 0
Cache-Control: must-revalidate, post-check=0, pre-check=0
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=Beethoven.wma;
Content-Transfer-Encoding: binary
Content-Length:
but the file location does exist.
The script will not recognize root paths such as /usr/sites/mywebsite.com/www/folder/
Now, what should I do?
Shouldn't it be able to find http:// locations?
Posted: Tue Aug 26, 2003 12:31 pm
by volka
there are functions that can only handle local files (accessed through the localfile system) and those that operate with url_wrappers.
filesize() can only access local files
The script will not recognize root paths such as /usr/sites/mywebsite.com/www/folder/
why is that?
Posted: Fri Aug 29, 2003 10:17 am
by Emerald
Here is an update to my problem. My host have gave me this code to generate the download box.
Code: Select all
header( "Content-Type: application/force-download" );
header( "Content-Disposition: attachment; filename=Test.wma");
$fn=fopen( "download/folder/theFile.wma" , "r" );
fpassthru( $fn );
this works good when you physically type the file name...it will download & I can play the file, but fopen is having a problem with using $url.
I don't know if its because my files are .wma format because when $url is used & I want to play the song, Windows Media gives an error: "The file you are attempting to play has an extension that does not match the file format." And it will not play.
I have told $url (generated from a query using an [id]) to print; & it does give.. download/folder/theFile.wma
the same as physically typing it. Does fopen not like variables?
I haven't seen examples with people doing it.