Page 1 of 1

Want to track download, then redirect

Posted: Thu May 15, 2003 12:14 am
by architekt
I want to have it so that instead of directly linking to my file, I call a php script with the name and type of the file and then log the info in my database and then pass the link on to the user. I can do all the database stuff no problem, and have gotten all the way down to the part where I have both a relative path to the file and the full URL to the file. My problem is that now I have no clue how to actually let the user get the file.

I have 2 file types I need to worry about: MP3 and RealAudio. I thought you were supposed to do something like this:
header("Content-Type: audio/x-pn-realaudio"); for a realaudio file...and audio/mp3 for an mp3 file.


My problem is that nothing happens! you just see a blank page. My first guess was to just do:
header("location: " . $filename);

But for my realaudio file (a .ram file), it literallly opens the .ram file and displays it on screen instead of opening up realplayer and playing the .ram file. Same problem with MP3, it downloads it then displays it.

How can I get the browser to then pass off the link????? Thanks a ton for your help, I appreciate it.

Posted: Thu May 15, 2003 1:28 am
by volka
If you do open the link directly in your browser does it work?
The question is: does your webserver know that .ram files are of the mime-type audio/x-pn-realaudio?

Posted: Thu May 15, 2003 1:58 am
by architekt
yup, if I open the exact link directly in my browser real audio pops up. Or if i type in the .mp3 version, I'm able to download it. Maybe I'm just not including enough.....what exactly would you put? just a Content-type? or a content-type and a readfile()? or maybe a content-descriptor (uh, i don't remember if it's descriptor or not...sounds kind of likeit though)

Posted: Thu May 15, 2003 5:46 am
by patrikG
Quote from user-notes in http://www.php.net/header?
There is this nasty bug in IE 5 for Windows prior to service pack 2, described in Microsoft knowledgebase article Q281197 which causes a problem with redirecting.. if you submit a POST form to a page that uses header() to redirect to another page after processing the form data, then IE will not display some of the images on the page, if the user has an "external HTTP namespace handler" (RealDownload for example) installed. It took me a very long time to figure this out; I had no idea why my ads weren't displaying on IE for windows but worked fine everywhere else.
I don't remember where I found the workaround, but I am using this for image-downloads - works in all browser I've tested it with (IE, Netscape, Mozilla, Opera)

Code: Select all

<?php
if ($download)
	{
	header("Cache-control: private");
	header("Content-type: application/octet-stream");
	header("Content-Disposition: attachment; filename=".$image[name].".jpg");
    header("Content-length: ".filesize($filename)."\n");

    //send file contents
    $fp=fopen($filename, "r");
    fpassthru($fp);
	}

?>