4images Modifications / Modifikationen > Mods & Plugins (Releases & Support)
[Mod] CSV Export Of Images
(1/1)
J.Lond:
I need a CVS export of my images with the following export format:
image_name | image_url (direct Linux path) | image_hits | image_date | image_rating
Exports must be delimited by a pipe (|). I would like to be able to do separate csv files per individual image category.
Any help on this would be appreciated.
Best Regards,
Jason
Rembrandt:
Hi!
1.) insert in your Template/categories.html wherever you want :
--- Code: ---<a href="{downloadCSV}">CSV</a>
--- End code ---
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
J.Lond:
Thank you very much. I forgot to mention that each image needs to be on it's own line.
For Example:
image_name1 | image_url (direct Linux path) | image_hits | image_date | image_rating
image_name2 | image_url (direct Linux path) | image_hits | image_date | image_rating
image_name3 | image_url (direct Linux path) | image_hits | image_date | image_rating
Again, thank you for your assistance.
Best Regards
b-707:
I tried it. But I cannot find the output CSV-Files.
I looked for them in /my_path/data/and_subdirectories.
What must I do?
Thx in advance for your help.
Josef / b-707
Sunny C.:
Example: data/media/1/name.csv
Navigation
[0] Message Index
Go to full version