zencart export批量导出数据,生成csv操作

<?php
/**
 * 
 * export data to wp,ps,zc
 * eg.
 * <p>
 * export.php?f=wp&l=lang_id
 * </p>
 * @var unknown
 */
define('CRON_NOT_LOGIN_YES', true); // CSV
require_once ('includes/application_top.php');
@set_time_limit(0);
@ini_set('max_input_time', '9999');
$host = (isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']);
if (strpos($host, ':') !== false)
    $host = substr($host, 0, strpos($host, ':'));

//$_GET['f'] = isset($_GET['f']) ? $_GET['f'] : 'wp';
$_GET['min'] = isset($_GET['min']) ? (int)$_GET['min'] : null;
$_GET['max'] = isset($_GET['max']) ? (int)$_GET['max'] : null;
$limit = '';

if ($_GET['max'] !== null && $_GET['min'] !== null && $_GET['max'] > $_GET['min'])
    $limit = " LIMIT ".(int)$_GET['min'].", ".(int)$_GET['max'];

if (isset($_GET['f']))
{

    $lang_id = isset($_GET['l']) ? (int)$_GET['l'] : 3;
    $name = $host.date('Y-m-d-H-i-s').'.csv';
    // require (DIR_WS_CLASSES . 'currencies.php');

    $currencies = new currencies();

    $filed_format = '"v_products_model","v_products_image","v_products_name_1","v_products_description_1","v_products_url_1","v_specials_price",'.
        '"v_specials_last_modified","v_specials_expires_date","v_products_price","v_products_weight","v_last_modified","v_date_added","v_products_quantity",'.
        '"v_manufacturers_name","v_categories_name_1","v_categories_name_2","v_categories_name_3","v_categories_name_4","v_categories_name_5",'.
        '"v_categories_name_6","v_categories_name_7","v_tax_class_title","v_status","v_metatags_products_name_status","v_metatags_title_status",'.
        '"v_metatags_model_status","v_metatags_price_status","v_metatags_title_tagline_status","v_metatags_title_1","v_metatags_keywords_1",'.
        '"v_metatags_description_1","v_cate_meta_title_1_1","v_cate_meta_keywords_1_1","v_cate_meta_description_1_1","v_cate_meta_title_2_1",'.
        '"v_cate_meta_keywords_2_1","v_cate_meta_description_2_1","v_cate_meta_title_3_1","v_cate_meta_keywords_3_1","v_cate_meta_description_3_1",'.
        '"v_cate_meta_title_4_1","v_cate_meta_keywords_4_1","v_cate_meta_description_4_1","v_cate_meta_title_5_1","v_cate_meta_keywords_5_1",'.
        '"v_cate_meta_description_5_1","v_cate_meta_title_6_1","v_cate_meta_keywords_6_1","v_cate_meta_description_6_1","v_cate_meta_title_7_1",'.
        '"v_cate_meta_keywords_7_1","v_cate_meta_description_7_1","v_property_1"'."\n";



//  header("Pragma: public");
//  header("Expires: 0");
//  header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
//  header("Content-Type:application/force-download");
//  header("Content-Type:application/vnd.ms-execl");
//  header("Content-Type:application/octet-stream");
//  header("Content-Type:application/download");;
//  header('Content-Disposition:attachment;filename="'.$name.'"');
//  header("Content-Transfer-Encoding:binary");
//  $handle = fopen('php://output', 'w+');

    $csv_path = DIR_FS_CATALOG.''.$name;
    $handle = fopen(DIR_FS_CATALOG.''.$name, 'w+');

    switch ($_GET['f'])
    {
        case 'zc':

            $filed_format = '"v_products_model","v_products_image","v_products_name_3","v_products_description_3","v_products_url_3","v_specials_price",'.
                '"v_specials_last_modified","v_specials_expires_date","v_products_price","v_products_weight","v_last_modified","v_date_added","v_products_quantity",'.
                '"v_manufacturers_name","v_categories_name_1","v_categories_name_2","v_categories_name_3","v_categories_name_4","v_categories_name_5",'.
                '"v_categories_name_6","v_categories_name_7","v_tax_class_title","v_status","v_metatags_products_name_status","v_metatags_title_status",'.
                '"v_metatags_model_status","v_metatags_price_status","v_metatags_title_tagline_status","v_metatags_title_3","v_metatags_keywords_3",'.
                '"v_metatags_description_3","v_property_1"'."\n";
            fwrite($handle, $filed_format);

            break;

        case 'wp':
            $filed_format = 'csv_post_title,csv_post_post,csv_post_categories,csv_post_tags,csv_post_excerpt,csv_post_date,csv_post_author,csv_post_slug'."\n";
            fwrite($handle, $filed_format);
            break;
    }


    $products = $db->Execute("
    SELECT *
    FROM ".TABLE_PRODUCTS." p JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd ON (p.products_id=pd.products_id AND pd.language_id=$lang_id)
    ORDER BY p.products_id ASC
    ".$limit);

    while (!$products->EOF)
    {

        //$r = $products->fie
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值