本文整理汇总了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);
}
示例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();