|
|
|
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
?> | | |
|
| Simple pipe delimited file export program that downloads to a local machine Categories : PHP, Filesystem, Databases, MySQL, 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 | | | 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 | | | Easy upload class Categories : PHP Classes, Filesystem, HTTP, PHP | | | 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 | | | Execute a command to a string Categories : PHP, Program Execution, Filesystem | | | Using php3 to upload files, uploading files, file uploads. Categories : PHP, Filesystem, HTTP | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Introduction to Language Files Categories : PHP, Filesystem, Beginner Guides | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | php jump urls...the best way Categories : PHP, URLs, Filesystem | | | Simple way to replace a variable value in a .conf (.ini) file using a
webbrowser - the first stage of a complete universal configuration editor Categories : PHP, Regexps, Code Editors, Filesystem | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | Simple Password example Categories : PHP, Authentication, Security, HTTP | |
| | | | 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
| |
|
|
|