I am working on a site to get multiple pages of a book and make it one file for mobile users. The site is at http://bookgrabber.comze.com. Right now I am providing a download link to download the finished book. The download link is actually a link to downloadBook.php. Everything works fairly well and as expected, but when you click "save link as" the first word of the title of the book comes up in the save as dialog...Where is that coming from so I can alter it? It does not appear in the html of the page...
Here is what is on the downloadBook.php page:
header('Content-disposition: attachment; filename='.$_SESSION['bookName'].'.html');
header('Content-type: application/html');
echo $_SESSION['book'];
Thank you,
Todd
That's what your first header line is designed to do: tell the browser that the file should be downloaded and not displayed, and tell it what the filename should be.
header('Content-disposition: attachment; filename='.$_SESSION['bookName'].'.html');
That filename= part is telling the browser what the filename should be. It's getting cut off at the first space (only having the first word) because names with spaces should be surrounded by double quotes in a Content-disposition header:
header('Content-disposition: attachment; filename="'.$_SESSION['bookName'].'.html"');
Related
I have a site which allows clients to download files that they have purchased.
A link is sent to the customer which directs them to a page which checks if the link is valid, and if it is, allows them to download their product.
Here is an example of the link: http://www.psptubestop.com/dl/2z129a2.php?reference=6d556bde201a2fe4079874168&password=535864380ee2bc0f57cced3fe&pid=402
A lot of customers are saying that when they download, the .zip extension is missing, and I can't find the problem, it works fine on my machine, except when I do "save as", but even then some people are having problems.
Is there any way to allow them to download the file, and keep the .zip extension even if they press "save as"?
This is the code I am using to redirect them to the download...
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$originalfilename");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
Thanks for any help.
The problem could be that some files have spaces, in that case with your current code only the first part is used so loosing the extension part, to prevent such error you have to enclose the filename in double quotes, like so:
header('Content-Disposition: attachment; filename="'.$originalfilename.'"');
I am willing to bet it has something to do with there being a space in the filename seeing as the filename in the headers is PSP_Tubes_PSP_Tubes_Lisa_Cree_The Gift_6932.zip and the file wants to be save as PSP_Tubes_PSP_Tubes_Lisa_Cree_The.
Add a dummy GET parameter that looks like a filename.
...&fname=/foo.zip
I am using php to show the pdf
#readfile($actualfilename);
header('Content-type:pdf');
header('Content-Disposition: inline');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($actualfilename));
header('Accept-Ranges: bytes');
the problem is on the tittle bar it shows
and when I use
header('Content-type:application/pdf');
it prompts me to download the file and the same problem appears when I use
header('Content-Disposition: inline; filename='.$fakefilename.'');
This code shows pdf file in only firefox. I.E,chrome prompts me to download file?
Are you trying to change the browser's title bar text (or wherever it shows the file name)?
If so, you're out of luck here, because that won't work as it's up to the browser to decide how/where (if at all) show the file name.
However, there's some possible workaround: You could use server side tools, such as mod_rewrite in an Apache environment to redirect a request like download/readme.pdf behind the scenes to readfile.php?file=readme.pdf. In this case the browser won't know about the hidden rewrite and it will in fact display readme.pdf as the file name (even if the real file name or the script's name on the server side are different).
test.php code:
$path = 'audio.mp3';
header("Content-type: audio/mpeg");
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: inline; filename="'.$path.'"');
header("Content-length: ".filesize($path));
readfile($path);
html code:
<iframe src="test.php"></iframe>
this will play the .php as a .mp3, but i will not be able to access the navigation slider in the browser media player. i click on the slider in several different places, but nothing will happen. when i change the source to "audio.mp3" i am able to control the slider again. im pretty sure that it has something to do with the headers. any idea what headers i can use to fix this?
It actually has everything to do with what browser and plugin you are using, "streaming" mp3 or media files for that matter should not be done this way. Use any of the many open source and easy to use Flash players, they handle buffering, controls, display/hidden, and everything for you, for a mp3 file on your server.
I have links in my web page that point to PDFs, that are in my server.
I don't want want pdfs to be viewed in the browser bur directly downlodable when a user click on the link
just set the right header info. PHP file should look something like this.
<?
header('Content-disposition: attachment; filename=huge_document.pdf');
header('Content-type: application/pdf');
readfile('huge_document.pdf');
?>
as depicted here
http://webdesign.about.com/od/php/ht/force_download.htm
Regards
I have a script that generates data in csv format which is sent to the user along with a set of headers that tell the browser it is a .csv file. Everything works great when users (left)click on the link to the script, they are presented with a download dialog with the filename ending in .csv and it suggests using excel, or calc, to open it. However, when users right-click and choose Save As it is being saved with the php script name.
Here is the header code:
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
$val = date("m_d_Y_g_i");
Header('Content-Disposition: attachment; filename="personal_information_'.$val.'.csv"');
So again, when users left-click it saves the file as personal_information_date.csv; when they right click it saves as download.php. I'm using FF3. Oddly enough, IE7 does not have this problem.
Any ideas?
Use mod_rewrite to alias the file from file.csv to file.php, this is a browser issue rather than PHP because by saving the file it isn't running it before it is saving it.
So to summarise:
Link to personal_information_date.csv
Create a mod_rewrite rule that forwards personal_information_date.csv to download.php (e.g.: RewriteRule ^personal_information_date.csv$ download.php).
The HTTP client may ignore more than one content type header, the two other will be ignored - which of them? Depends on the browser implementation, therefor the different behaviour. The correct mime type is text/csv, not application/octet-stream! The content-disposition header is correct for the download.
I believe that setting three different mimetypes doesn't help
what's $val ? Is this known content or user provided - e.g. could it contain nasty characters (like ") or even linebreaks, e.g. introduce new HTTP header lines?
have a look at the HTTP-Headers that arrive at the client. Either the Firefox built-in information or use LiveHttpHeaders (plugin to be found at the Mozilla site - logs all HTTP-Headers) - I'm sure there are more/other plugins for FF available.
Hope this helps.