View Full Version : force download using PHP
claudio
September 21st, 2003, 09:20 PM
When i use the getURL action to link to mp3 files, IE tries to open the file instead of launching the save as dialog window.
Anybody knows how to use PHP to work around that?
:cyclops:
Jubba
September 21st, 2003, 09:31 PM
i'm working on it. give me about 10 minutes :0
claudio
September 21st, 2003, 09:37 PM
Thanks Jubba :)
Jubba
September 21st, 2003, 09:46 PM
found the answer. :) http://forums.free2code.net/view.php?tid=8360
I was writing my own code, but then I decided to consult google because if its already been written then I don't want to waste my time.. and here it is...
<?php
$filename = $_GET['filename'];
if (ereg(".mp3$", $filename)) {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($filename).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
}
?>
if you need it to be explained then let me know :)
oh, and I tested it. It worked for me. :)
claudio
September 21st, 2003, 09:49 PM
Man, i searched google i swear! :blush:
Now i need to know the code i need to use on the flash button.
Jubba
September 21st, 2003, 09:52 PM
well the html code would be:
a href="thispage.php?filename=someMP3.mp3"
so I'm assuming the AS would be:
getURL("thispage.php?filename=someMP3.mp3", "_blank", "GET");
something like that would work...
Oh, and don't worry about searching google. It took me a lot of searching to find it. The keywords I used were: "PHP header content MP3 application download" you really have to know what you're looking for. lol
claudio
September 21st, 2003, 09:56 PM
Yea, i tried using every different keyword you can imagine!
Let me try the code, thanks again Jubba
=)
Jubba
September 21st, 2003, 10:01 PM
lol the only way I got that response was because I used all the keywords at the same time. I like to think of myself as the google-master :)
ahmed
September 21st, 2003, 10:09 PM
nice one Vash-Stmpd :beam:
claudio
September 21st, 2003, 10:48 PM
Thanks Jubba, worked like a charm :)
claudio
September 21st, 2003, 11:36 PM
Hey Jubba, i was wondering if you could help me with something else... how can i use PHP to count the number of downloads?
ahmed
September 21st, 2003, 11:42 PM
http://www.kirupaforum.com/forums/showthread.php?threadid=31738&highlight=database ;)
BTW, im working a php-tool that i'll be giving out for free once im done writing it, and it basically does what your looking for, tracks how many times a link have been clicked.. i guess you could make use of that :)
claudio
September 21st, 2003, 11:50 PM
Thanks for the reply ahmed, but do i really need to use sql?
And yes, i will be waiting for your php download tool :)
Jubba
September 21st, 2003, 11:52 PM
well you need a way to store the informatoin somehow. sql is pretty much your best option.
ahmed
September 21st, 2003, 11:54 PM
well, my" tool" is mysql-based.. for jubba's post, you might be able to pull this off with plain text files or xml, but mysql, i say, requires pretty much the least work of all three methods :)
claudio
September 21st, 2003, 11:55 PM
thanks guys... im going to read about sql cause i know nothing about that.
ahmed
September 21st, 2003, 11:57 PM
mySQL is well-worth knowing :beam:
claudio
September 21st, 2003, 11:58 PM
any tip or advice for a newbie?
good ressources, books?
Jubba
September 22nd, 2003, 12:51 AM
nah. mysql is pretty straightforward. just find some simple PHP database stuff. you'll get the hang of it really quick
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.