Hi!
1.) insert in your Template/categories.html wherever you want :
<a href="{downloadCSV}">CSV</a>
2.) search in categories.php:
"random_cat_image" => $random_cat_image
insert above:
"downloadCSV" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id."&action=downloadCsv"),
3.) search:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
insert above:
if ($action == "downloadCsv"){
//Select the Tablefields
$tableFieldsArray = array(
'image_name',
'image_media_file',
'image_hits',
'image_date',
'image_rating',
);
// Select the delimiter between the tablefields, e.g.: ", ; : | * "
$delimiter = "|";
$path = ROOT_PATH.MEDIA_DIR."/".$cat_id."/csv/";
if(!is_dir($path)){
mkdir($path,0777);
chmod($path,0777);
}
$tableFields = implode(",",$tableFieldsArray);
$sql = "SELECT ".$tableFields."
FROM ".IMAGES_TABLE."
WHERE cat_id = ".$cat_id."
";
$result = $site_db->query($sql);
if($result){
$tableFields = array(implode("$delimiter",$tableFieldsArray));
$file_name = $cat_cache[$cat_id]['cat_name'].".csv";
$output = fopen($path."/".$file_name, "w");
fputcsv($output,$tableFields);
while ($row = mysql_fetch_assoc($result)){
$row['image_media_file'] = "./data/media/".$cat_id."/".$row['image_media_file'];
$row['image_date'] = ($row['image_date']) ? format_date($config['date_format']." ".$config['time_format'], $row['image_date']):$row['image_date'];
fputcsv($output, array(implode("$delimiter",$row)));
}
}
if (is_dir($path)) {
$size = @filesize($path."/".$file_name);
header("Content-type: application/x-unknown");
header("Content-length: $size\n");
header("Content-Disposition: attachment; filename=$file_name\n");
readfile($path."/".$file_name);
exit;
}
} // END $action == "csv"
mfg Andi