Moved download logic from js to download.php