Jump to content

Recommended Posts

Summary: A DELETE query interferes with Windows Media Player?

 

Background: I run a registration-required php/mysql site that serves .wma files.  Works great.  At one point, a member posted a link to one of my files on another web site, and people could download the file without registering/logging in. 

 

So I decided to use PHP to readfile($file) to logged in users only, and .htaccess the files directory.  Works like a charm.  Like so:

	header('Content-Type: audio/x-ms-wma');
header('Content-Disposition: attachment; filename="whateverfile.wma"');
header('Content-Transfer-Encoding: binary');
readfile($file);

 

Had to add the mime type to apache but no problem.

 

So now I've decided I'd like to stream files to people, instead of them having to download them fully first.  Since I don't run a windows media server, i do it the pseudo-stream method, by providing the user with a dynamically generated .asx (using php of course) that opens for them in their media player, and begins download/playing the file.

 

Works great, EXCEPT: i have to disable the .htaccess in order to allow media players to access the file, which I don't want to do.

 

So... I decided to try and implement the same system with streams as with downloads.  The obstacle there is that a media player cant exactly log in to my site, afaik.  So I decided to create a database table called 'stream'.  When the .asx is generated, a user ID, file ID, and random passkey are inserted into the stream table, and the link given in the .asx is a php script that is supposed to check the passkey corresponding to the user ID in the table, and if it matches, delete the entry completely, and readfile() the file corresponding to the file_id.

 

Struggled with this beast for hours and hours.  When the script includes/executes the DELETE FROM query, WMP will not play the file. 

 

I've tried different incarnations of the script, executing the query at different times, even trying some fancy redirects.  I even tried using an UPDATE query instead of DELETE, but again, WMP refuses.  Substituting with a SELECT query causes no problems.  Also tried closing and reopening the msyql connection to no avail.

 

If i simply comment out the query, WMP has no problems. 

 

As a test, i put the link within the .asx inside my browser and hit go, and it downloaded the file, even with the delete query intact.

 

So... What the heck? Nothing makes any sense to me here.  Any input (or alternative method) is greatly appreciated.

 

Here's the stream.php code:

<?php
session_start();
require_once ("./include/session_init.php");

mysql_connect($_SESSION['MYSQL_SERVER'],$_SESSION['MYSQL_LOGIN'],$_SESSION['MYSQL_PASS'])
                   or die("Unable to connect to SQL server");
    mysql_select_db($_SESSION['MYSQL_DB']) or die("Unable to select database");
    
$query1 = "SELECT pass FROM stream WHERE user_id = ".$_GET['user_id'];
    $result1 = mysql_query($query1) or die("Invalid query (login): " . mysql_error());
    $row = mysql_fetch_assoc($result1);
    $pass = $row['pass'];

$query2 = "DELETE FROM stream WHERE user_id = ".$_GET['user_id']." LIMIT 1"; 
$result2 = mysql_query($query2); or die("Invalid query (login): " . mysql_error());

$query = "SELECT path, name FROM files WHERE file_id = ".$_GET['file_id'];
$result = mysql_query($query) or die("Invalid query (login): " . mysql_error());
$row = mysql_fetch_assoc($result);
$file = $row['path'].$row['name'];

    if ($_GET['pass'] == $pass)
{
header('Content-Type: audio/x-ms-wma');
header('Content-Disposition: attachment; filename="'.$row['name'].'"');
header('Content-Transfer-Encoding: binary');
readfile($file);
//header("Location: stream_go.php?FILE=".$file);
}
else {
 exit;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/39401-extremely-challengingbizarre-problem/
Share on other sites

Guest
This topic is now 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.