Autodownload in PHP?

cursedpsp

New Member
Messages
237
Reaction score
0
Points
0
Hi i was wondering how to autodownload a url, like if it was a HTML file i wouldnt view it but it asked me to download - can someone tell me how to do it please?
Edit:
Anyone??
 
Last edited:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
well...you could always create a zip file...and then have them download that...i will do some research though
Edit:
NVM..still searching
 
Last edited:

woiwky

New Member
Messages
390
Reaction score
0
Points
0
PHP:
$file = 'path/to/file/name.ext';
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=$file");

readfile($file);
That should open a download dialog box as soon as it's executed.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
This has more headers and has a counter function! :p

PHP:
<?php
//File on server
$file = "Levy.dat";
//Filename when downloaded
$file2 = "Levy.jar";
//Using counter?
$counter = true;
//If true, counterfile:
$counterfilename = "Levy.txt";

// Headers for download:
header('Content-Type: application/octet-stream');
header("Content-Length: ".filesize($file));
header('Content-Disposition: attachment; filename="'.$file2.'"'); 
header('Content-Transfer-Encoding: binary');

readfile($file);
if(!$counter) exit;
@$counterfile = fopen($counterfilename,"r");
@$num = (int) fread($counterfile,filesize($counterfilename));
@fclose($counterfile);
@$counterfile = fopen($counterfilename,"w");
@$num++;
@fwrite($counterfile,$num);
@fclose($counterfile);
?>
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Better to give someone only what they ask for and let them apply it as they see fit ;-)
 

phpasks

New Member
Messages
145
Reaction score
0
Points
0
PHP:
<?php
$downloadurl =  $path."/".$abspath . trim($filename);

if (file_exists($downloadurl) && strlen($filename)!=0)
{
    $size = filesize($downloadurl);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false);
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".$filename."\";");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".$size);
    readfile($downloadurl);
} else {
    tep_redirect("index.php");
    exit;
}
?>


This is download file code. You can used it.

Asif
http://www.phpasks.com
 

cursedpsp

New Member
Messages
237
Reaction score
0
Points
0
i need to use a form - when the user enters a url, it downloads it - but i dont know which variable is which?
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Depending on what script you're using:
phpask's: $downloadurl
mine: $file ($file2 as downloaded name)
woiwky: $file
 
Top