|
|
|
The following code takes a file name as a parameter and then forces the browser to download that file.
|
<?
function force_download($file)
{
$dir = "../log/exports/";
if ((isset($file))&&(file_exists($dir.$file))) {
header("Content-type: application/force-download");
header('Content-Disposition: inline; filename="' . $dir.$file . '"');
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($dir.$file));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile("$dir$file");
} else {
echo "No file selected";
} //end if
}//end function
?> | | |
|
| Execute a command to a string Categories : PHP, Program Execution, Filesystem | | | Simple pipe delimited file export program that downloads to a local machine Categories : PHP, Filesystem, Databases, MySQL, HTTP | | | How to let a user download a picture by clicking on it instead of needing to right click and Save-As. Categories : HTTP, PHP, HTML and PHP, Filesystem | | | 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 | | | Using php3 to upload files, uploading files, file uploads. Categories : PHP, Filesystem, HTTP | | | 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 | | | Remote File Size Categories : PHP, Filesystem, HTTP, Sockets | | | Easy upload class Categories : PHP Classes, Filesystem, HTTP, PHP | | | redirect redirection ip address authentication authenticate addr Categories : Authentication, HTTP, Network, PHP | | | A function to check if a URL exists Categories : PHP, CURL, HTTP | | | The first step Guest Book ... ^^ Categories : MySQL, PHP, Apache, HTML, HTTP | | | PHP Transfer data from text file to Mysql Table Categories : PHP, PHP Classes, Filesystem, Databases, MySQL | | | Read a file with strings and create a new file with the
first half of each string Categories : PHP, Strings, Filesystem | | | windows nt php/3 file upload script Categories : Filesystem, PHP, IIS, WinNT, Web Servers | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | |
| | | | Jose Santos wrote : 1328
This is a very good code example, and very useful to download or export to file !!
| | | | walid yasen wrote : 1363
hi i use that code but have all this error, and i`m sure its form me , can yu help me why that error happen.
"Warning: Cannot modify header information - headers already sent by (output started at /home/../..../.../fdownload.php:1) in /home/.../../../fdownload.php on line 8
Warning: Cannot modify header information - headers already sent by (output started at /home/.../.../..../fdownload.php:1) in /home/.../.../.../fdownload.php on line 9
Warning: Cannot modify header information - headers already sent by (output started at /home/..../.../.../fdownload.php:1) in /home/.../.../.../fdownload.php on line 10
Warning: Cannot modify header information - headers already sent by (output started at /home/../../.../fdownload.php:1) in /home/.../../../fdownload.php on line 11
Warning: Cannot modify header information - headers already sent by (output started at /home/.../.../.../fdownload.php:1) in /home/.../.../../fdownload.php on line 12
Warning: Cannot modify header information - headers already sent by (output started at /home/.../.../.../fdownload.php:1) in /home/../../../fdownload.php on line 13
| | | | berber berberon wrote : 1364
Looks like you have a space somewhere in your file sent before the header info is sent. look for empty lines in the begining of your code.
| | | | dean williams wrote : 1379
why does everyone use <? ... ?>
This is NOT correct and does NOT work on all servers, please use the PHP standards...
<?php ... ?>
Anyone having problems can try that...
| | | | xgrapher xxx wrote :1688
I plopped the code on a php which I call upon from page, eg: xgrapher.com/download.php?file=test.mpg and it worked perfect. Thanks!
However, if I went back and tried downloading another file, it would simply terminate the file which is being downloaded.
I guess its because the variables are reserved till the download is completed. Could you please help?
Thanks,
xgrapher
| |
|
|