All I originally wanted to do was count how many times my videos were being downloaded.
I'm missing something here and I don't know what it is... I've just started picking up php, so my experience is amateurish at best.
I'm just trying to set up a forced download page that counts downloads and prompts to either Open (stream) or Save As. Currently, when anyone tries to Stream, they get a corrupt file prompt in Windows Media Player using IE. FF downloads the file entirely and then launches Windows Media Player and works fine...
I've hit up php.net, I still can't get it. I would greatly appreciate any help that might get me working properly.
If you guys have ANY other options on how I can do this, I'd greatly appreciate it. I'm about to put up a new video, and I'd really like to get an accurate count as to how many downloads it gets, without users reporting errors all over the place.
The link is:
http://www.ecoyne.com/ecoyne_vids.php
The code I'm using is this:
Code:
# Protect Script against SQL-Injections
$id = intval($_GET[id]);
# setup SQL statement
$sql = "SELECT * FROM tblVideos WHERE ID='$id'";
# execute SQL statement
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
# display results
while ($row = mysql_fetch_array($result)) {
$filename= $row['FileName'];
$filesize= $row['Size'];
$fileurl = 'http://www.ecoyne.com/videos/' .$filename;
$counter = $row['Counter'];
// Add 1 to the counter value from the array in $row
$counter += 1;
$sql2 ="UPDATE tblVideos SET Counter='$counter' WHERE ID = '$id'";
$result2 = mysql_query($sql2) or die('Query failed. ' . mysql_error());
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch ($file_extension) {
case "wmv": $ctype="video/x-ms-wmv"; break;
default: $ctype="application/force-download";
}
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: video/x-ms-wmv");
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
set_time_limit(0);
@readfile("$fileurl") or die("File not found.");
}
//Close sql Connection
mysql_close($conn);
?> Thanks greatly in advance!