当前位置: 首页>>代码示例>>PHP>>正文


PHP CSV::import方法代码示例

本文整理汇总了PHP中CSV::import方法的典型用法代码示例。如果您正苦于以下问题:PHP CSV::import方法的具体用法?PHP CSV::import怎么用?PHP CSV::import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSV的用法示例。


在下文中一共展示了CSV::import方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import

 /**
  * Import data
  * @TODO write to tmp table for better record tracking
  */
 public function import()
 {
     $newData = array();
     $total = 0;
     if (!empty($_FILES['csvFile']['name']) && !empty($_FILES['csvFile']['tmp_name'])) {
         require_once 'csv.class.php';
         $csv = new CSV();
         $data = $csv->import($_FILES['csvFile']['tmp_name']);
         foreach ($data as $item) {
             $newData[] = $this->create($item, false);
             $total++;
         }
         $status = 'success';
         $message = 'Data was imported';
     } else {
         $status = 'failed';
         $message = 'File did not upload';
         $newData[] = array();
     }
     //$item = $item->toArray();
     //$data[] = $item;
     return $this->makeJson($status, $message, $total, $total, $newData);
 }
开发者ID:Vitaliz,项目名称:RAD-UI,代码行数:27,代码来源:crud.class.php

示例2: isset

}
require_once $SYSTEM_ROOT . '/core/include/init.inc';
$GLOBALS['SQ_SYSTEM']->setCurrentUser($GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user'));
$assetid = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 0;
$asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, 'data_source_csv');
if (empty($asset)) {
    echo "You need to supply a CSV Data Source assetid as the second argument\n";
    print_usage();
    exit;
}
if ($_SERVER['argc'] < 4) {
    echo "You need to supply the path to CSV file as the third argument\n";
    print_usage();
    exit;
}
$filepath = $_SERVER['argv'][3];
require_once SQ_FUDGE_PATH . '/csv/csv.inc';
$GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
$csv = new CSV($filepath);
$csv->import();
$asset->setAttrValue('cached_content', $csv->values);
// overwrite the cache with the new content
$asset->setResultSet(array(), $asset->name);
$asset->getResultSet($asset->name);
$asset->saveAttributes();
// set last update time if forcibly required
$FORCE_UPDATE = isset($_SERVER['argv'][4]) ? $_SERVER['argv'][4] : 'n';
if (strtolower($FORCE_UPDATE) == 'y') {
    $asset->_updated();
}
$GLOBALS['SQ_SYSTEM']->restoreRunLevel();
开发者ID:joshgillies,项目名称:mysource-matrix,代码行数:31,代码来源:replace_csv_data_source_file.php


注:本文中的CSV::import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。