Question

I'm trying to create a .csv file with the following code:

public function export_modis_categories_xml(){  
header('Content-Type: application/excel');
header('Content-Disposition: attachment; filename="category_export.csv"');    
$category_rs = $this->db->query('
  SELECT        
    '.DB_PREFIX.'category.category_id, 
    '.DB_PREFIX.'category.parent_id, 
    '.DB_PREFIX.'category_description.name, 
    '.DB_PREFIX.'category_description.description 
  FROM          
    '.DB_PREFIX.'category
  INNER JOIN    
    '.DB_PREFIX.'category_description
  ON    
    '.DB_PREFIX.'category.category_id = '.DB_PREFIX.'category_description.category_id
');
error_log($category_rs);
$category_rs = $category_rs->rows;
$category_export_array = array();
$i = 0;
foreach($category_rs as $cat){
  $category_id  = ($category_rs[$i]['category_id']  =! '' ? $category_rs[$i]['category_id'] : '');
  $parent_id    = ($category_rs[$i]['parent_id']    =! '' ? $category_rs[$i]['parent_id']   : '');
  $name         = ($category_rs[$i]['name']         =! '' ? $category_rs[$i]['name']        : '');
  $description  = ($category_rs[$i]['description']  =! '' ? $category_rs[$i]['description'] : '');

  $category_export_array[$i] = $category_id.';'.$parent_id.';'.$name.';'.$description;      
  $i++;  
}

$fp = fopen('php://output', 'w');
$header_array = array('headers'=>'categorie_id;parent_id;name;description');
fputcsv($fp, $header_array);
fputcsv($fp, $category_export_array);
fclose($fp);  
} 

This worked on one site, as it is a OpenCart plugin, but not on another site.

The weird thing is, I don't get any error. Not in the error log or in web view. It doesn't give me file, and the site doesn't go blank...

Was it helpful?

Solution

I've found the error, it was never in my code..

The form that calls the function wasn't sending the right POST name, so the function wasn't triggerd.

Sorry for bothering everyone with my stupidity..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top