|
|
|
| Title : |
How to force the user to download a file instead of opening it up in an
controlled environment within the browser (i.e. MS Word/Adobe Acrobat) |
| Categories : |
Browsers, PHP, HTTP |
 Chris Sano |
| Date : |
Jul 10th 2000 |
| Grade : |
3 of 5 (graded 5 times) |
| Viewed : |
12726 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Chris Sano |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
I wrote this snippet of code to force the user to download my resume to their hard drives
rather than opening it up in the browser (since this has been known to cause some problems
on different platforms).
Files to be downloaded:
resume.doc, resume.rtf, resume.pdf
Link:
[ <a href="resume.php3?application=application/msword&fileName=resume.doc">.doc</a> ]
Variable explanations:
$application was set as application/msword for the .doc and .rtf files and application/octet-
stream for the .pdf file
$fileName was the file to be downloaded (resume.doc, resume.rtf, or resume.pdf)
And finally, the code:
(nothing other than what is below should be in the php file)
<?
$file = fopen("$fileName","r");
header("Content-type: $application");
header("Content-Disposition: attachment; filename=$fileName");
header("Content-Description: PHP3 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
fpassthru($file);
fclose($file);
?>
|
|
| Browser Detection, Redirection Type, MSIE, MOZILLA, Netscape Navigator, NS, $HTTP_USER_AGENT, HTTP_USER_AGENT Categories : PHP, HTTP, Browsers, HTML and PHP | | | Produces browser-safe strings while preserving HTML tags. Categories : Strings, HTTP, PHP, HTML and PHP | | | Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals. Categories : PHP, Filesystem, Cache, Sockets, HTTP | | | This gets the http response headers for a given url and returns them in an assoc array. i.e. to test if a url exists: $array = get_http_headers($url); if($array[result]=200) { } Categories : HTTP, Arrays, PHP | | | A simple script to count and report hits and the last
modification time of an HTML page. Requires MySQL support
(other DBs should work too, except possibly mSQL). Categories : HTTP, MySQL, PHP, Databases | | | Identify and log search engine access (spiders, robots, etc.) to a page. Categories : HTTP, Environment Variables, PHP, MySQL, Databases | | | $REMOTE_HOST does not return a value. Categories : PHP, Global Variables, HTTP | | | Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem | | | Remote File Size Categories : PHP, Filesystem, HTTP, Sockets | | | Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP Categories : PHP, HTTP, Regexps | | | valid link! Categories : HTTP, URLs, PHP | | | The following snippet gives complete info about all submitted
HTTP_POST_VARS and HTTP_GET_VARS Categories : Variables, HTTP, PHP | | | Upload Script, Upload File Script, Input Type="File" Categories : PHP, HTML and PHP, HTTP | | | Using php3 to upload files, uploading files, file uploads. Categories : PHP, Filesystem, HTTP | | | This script shows you the 7th latest php items from the mailing list archive on zend.com Categories : HTML, HTML and PHP, HTTP, PHP | |
| |
| | | | | Max Power wrote :658
that doesnt work in ie5.5, bugs
| |
|
|