<?php
$file = basename($_GET["code"]).".csv";
if (file_exists($file)) {
    header('Location: '.$file);      
} else {
  $page = file_get_contents("http://bitcoincharts.com/charts/chart.json?m=".$_GET["code"]."&i=Daily");
  $page = str_replace("[[", "", $page);
  $page = str_replace("], [", "\n", $page);
  $page = str_replace("]", "", $page);
  echo "date,price,...";
  echo "$page";
}
?>
