I have the following script to do a CSV export, but its use is to upload to Google Products and I don't think that system likes CSV, only .txt.
I can Save As the CSV as a txt file, but be better if I could export it as .txt.
Here's the code:
Code: Select all
<?php
$cookietype = $_COOKIE['type'];
$todaydate = date('Y-m-d');
if ($cookietype == "admin") {
include "dbconn.php";
$csv_output = '"id","title","description","price","image link","link","condition","availability","brand"';
$csv_output .= "\015\012";
$result = mysql_query("SELECT * FROM products WHERE pause = 'off'");
while($row = mysql_fetch_array($result))
{
$title = "$row[title]";
$findtitle ="/ /";
$replacetitle ="-";
$titlereplace = preg_replace ($findtitle, $replacetitle, $title);
$categ = "$row[catname]";
$findcateg ="/ /";
$replacecateg ="-";
$categreplace = preg_replace ($findcateg, $replacecateg, $categ);
$subcateg = "$row[subname]";
$findsubcateg ="/ /";
$replacesubcateg ="-";
$subcategreplace = preg_replace ($findsubcateg, $replacesubcateg, $subcateg);
$csv_output .= '"'.$row[id].'","'.$row[title].'","'.$row[title].'","'.$row[price].'","http://www.site.co.uk/images/'.$row[photoprimary].'","http://www.site.co.uk/product/'.$row[catid].'/'.$categreplace.'/'.$row[subid].'/'.$subcategreplace.'/'.$row[id].'/'.$titlereplace.'","New","In Stock","'.$row[manufacturer].'"';
$csv_output .= "\015\012";
}
//You cannot have the breaks in the same feed as the content.
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv; filename=Google_" . date("Y-m-d") .".csv");
print $csv_output;
exit;
mysql_close($sqlconn);
echo "Extract in progress - close page when completed.";
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/'>";
}
?>