I have a file that is downloaded though my site. I want to count the number of downloads. I have achieved it with the following code:
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("a7871565_first",$dbhandle)
or die("Could not select examples");
$result = mysql_query("select * from downloads");
$row = mysql_fetch_array($result);
$count= $row{'download'};
$count= $count+1;
$result = mysql_query("UPDATE downloads SET download =$count");
echo "<script>";
$url = "http://www.mohammediatechnologies.in/apps/TubeMateHd.apk";
echo "window.open('$url');".PHP_EOL;
echo "</script>";
It does update the database with count as well as downloads the file but when the user clicks on the download button he is redirected to the file named download.php containing the code above. The user is presented with a blank screen which is something I don't want. The file download is opening in another window that is blocked as it is considered as a popup.
What I want to achieve is when the user clicks on the download link, the user stays on the same page, the database updates and the file is downloaded.