Jump to content

PHP streaming file loops when it's not suppose to


bfaubion

Recommended Posts

Hi all, I've been running into some issues trying to stream .mp3 files, specifically Safari/Flash... Firefox works great. I'm about to throw in the towel on this one and try another streaming solution, so I thought I'd reach out and connect with the PHP pros here before trying something else.

 

Basically, the PHP streamer takes a track guid variable and token variable(MD5), looks up the field in the DB, gets the url and then proceeds to stream the file with no caching, and keeping the URL hidden from the user so they can't download it. The token variable is there to assure that the url is only used once. Once it is, the script will not allow the stream if the token/track guid combo already exists in the DB. The problem with the looping is that once that token has been used it won't stream the track, which is how it's suppose to work, sans looping. I've put an MYSQL INSERT into the code to verify that it does loop.. usually I see 3- :wtf:5 consecutive entries in the DB for that token. So Firefox does not do this.. and I gather it's something to do with how the client streams with the "readfile" function.

 

Pasted below is some code to show the headers and the readfile function I am using. I can post the rest of the script if need be.

 

//$path and $tokenApproved are variables i set earlier in the script

date_default_timezone_set('GMT');
$date = date(DATE_RFC822);
$filesize = ffilesize($path);
$shortlen = $filesize - 1;

//ffilesize() is a custom filesize function

if($tokenApproved)
{
header("Content-type: audio/mpeg");
header("Content-Length: $filesize");
header('Content-Range: bytes 0-'.$shortlen.'/'.$filesize);
header("Expires: $date");
header('Content-Disposition: filename="eztunesaudio.mp3"');
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
readfile($path);
}

//eztunesaudio.mp3 is just a default name I give the stream

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.