buggedcom
01-10-2003, 06:25 PM
Hello everyone,
I'm developing a photogallery component that is really too much bloody work to be fun but i have nearly completed it. I am currentley working on using php to forcedownload images rather than having them open them up in browser windows. This is all fine and dandy and I already have a forcedown script... and all is well. What i am trying to do is use an antileaching script with the force download script i already have (below) but any of the scripts i can find i have absolutley no idea how to combine the two as i have no idea about php.
force download script
<?php
$file = $_GET["file"];
download($file);
function download($file, $name = false, $type = false, $down = true) {
if(!file_exists($file)) exit;
if(!$name) $name = basename($file);
if($down) $type = "application/force-download";
else if(!$type) $type = "application/download";
$disp = $down ? "attachment" : "inline";
header("Content-disposition: ".$disp."; filename=$name");
header("Content-length: ".filesize($file));
header("Content-type: ".$type);
header("Connection: close");
header("Expires: 0");
set_time_limit(0 ) ;
readfile($file);
exit;
}
?>
My gallery example page is at http://photogallery.buggedcom.co.uk . Note that although i have the script fully working on my machine i have not yet uploaded it to my server, and the one on the server is not working 100% see the note on the example.
You will also notice that in certain browsers the script causes a window to be opened. I do not want this to happen. I don't know if it can be self closed or there is a script which doesn't do this. Obviously i don't want just to refer the script to be loaded in _self as this will overwrite the flash movie. Anyway and ideas will be greatly appriciated.
Thanks
I'm developing a photogallery component that is really too much bloody work to be fun but i have nearly completed it. I am currentley working on using php to forcedownload images rather than having them open them up in browser windows. This is all fine and dandy and I already have a forcedown script... and all is well. What i am trying to do is use an antileaching script with the force download script i already have (below) but any of the scripts i can find i have absolutley no idea how to combine the two as i have no idea about php.
force download script
<?php
$file = $_GET["file"];
download($file);
function download($file, $name = false, $type = false, $down = true) {
if(!file_exists($file)) exit;
if(!$name) $name = basename($file);
if($down) $type = "application/force-download";
else if(!$type) $type = "application/download";
$disp = $down ? "attachment" : "inline";
header("Content-disposition: ".$disp."; filename=$name");
header("Content-length: ".filesize($file));
header("Content-type: ".$type);
header("Connection: close");
header("Expires: 0");
set_time_limit(0 ) ;
readfile($file);
exit;
}
?>
My gallery example page is at http://photogallery.buggedcom.co.uk . Note that although i have the script fully working on my machine i have not yet uploaded it to my server, and the one on the server is not working 100% see the note on the example.
You will also notice that in certain browsers the script causes a window to be opened. I do not want this to happen. I don't know if it can be self closed or there is a script which doesn't do this. Obviously i don't want just to refer the script to be loaded in _self as this will overwrite the flash movie. Anyway and ideas will be greatly appriciated.
Thanks