• [Mod] CSV Export Of Images 5 0 5 1
Currently:  

Author Topic: [Mod] CSV Export Of Images  (Read 15480 times)

0 Members and 1 Guest are viewing this topic.

Offline J.Lond

  • Newbie
  • *
  • Posts: 23
    • View Profile
[Mod] CSV Export Of Images
« on: September 25, 2014, 05:19:23 AM »
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

  • Guest
Re: [Mod] CSV Export Of Images
« Reply #1 on: October 12, 2014, 07:19:30 PM »
Hi!

1.) insert in your Template/categories.html wherever you want :
Code: [Select]
<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."&amp;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

Offline J.Lond

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: [Mod] CSV Export Of Images
« Reply #2 on: October 25, 2014, 09:05:49 AM »
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

Offline b-707

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: [Mod] CSV Export Of Images
« Reply #3 on: September 11, 2021, 01:24:19 PM »
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

Offline Sunny C.

  • Addicted member
  • ******
  • Posts: 1.808
  • I ♥ 4I
    • View Profile
Re: [Mod] CSV Export Of Images
« Reply #4 on: October 10, 2021, 02:38:52 PM »
Example: data/media/1/name.csv