本文整理汇总了PHP中parseCSV::save方法的典型用法代码示例。如果您正苦于以下问题:PHP parseCSV::save方法的具体用法?PHP parseCSV::save怎么用?PHP parseCSV::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parseCSV
的用法示例。
在下文中一共展示了parseCSV::save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process_step
/**
* Process a step
*
* @since 2.6
* @return bool
*/
public function process_step()
{
$more = false;
if (!$this->can_import()) {
wp_die(__('You do not have permission to import data.', 'edd'), __('Error', 'edd'), array('response' => 403));
}
$csv = new parseCSV();
$csv->auto($this->file);
if ($csv->data) {
$i = 0;
$more = true;
foreach ($csv->data as $key => $row) {
// Done with this batch
if ($i >= 19) {
break;
}
// Import Download
$args = array('post_type' => 'download', 'post_title' => '', 'post_name' => '', 'post_status' => '', 'post_author' => '', 'post_date' => '', 'post_content' => '', 'post_excerpt' => '');
foreach ($args as $key => $field) {
if (!empty($this->field_mapping[$key]) && !empty($row[$this->field_mapping[$key]])) {
$args[$key] = $row[$this->field_mapping[$key]];
}
}
$download_id = wp_insert_post($args);
// setup categories
if (!empty($row[$this->field_mapping['categories']])) {
$categories = $this->str_to_array($row[$this->field_mapping['categories']]);
if (!empty($categories)) {
wp_set_object_terms($download_id, $terms, 'download_category');
}
}
// setup tags
if (!empty($row[$this->field_mapping['tags']])) {
$tags = $this->str_to_array($row[$this->field_mapping['tags']]);
if (!empty($tags)) {
wp_set_object_terms($download_id, $terms, 'download_tag');
}
}
// setup price(s)
if (!empty($row[$this->field_mapping['price']])) {
$price = $row[$this->field_mapping['price']];
if (is_numeric($price)) {
update_post_meta($download_id, 'edd_price', edd_sanitize_amount($price));
} else {
$prices = $this->str_to_array($price);
if (!empty($prices)) {
$variable_prices = array();
foreach ($prices as $price) {
// See if this matches the EDD Download export for variable prices
if (false !== strpos($price, ':')) {
$price = array_map('trim', explode(':', $price));
$variable_prices[] = array('name' => $price[0], 'amount' => $price[1]);
}
}
update_post_meta($download_id, 'edd_variable_prices', $variable_prices);
}
}
}
// setup files
// setup other metadata
// Once download is imported, remove row
unset($csv->data[$key]);
$i++;
}
$csv->save();
}
return $more;
}
示例2: die
echo "<h1 style='text-align:center;'>\n Something went wrong with the database..\n </h1>\n";
echo $e->getMessage();
echo '<br>';
var_dump($e->getTraceAsString());
die(1);
}
/*
for debug, append the data to a csv as well
*/
// insert id in front
$vals = ['id' => $lastId] + $vals;
$csv = new parseCSV();
$csv->sort_by = 'email';
$csv->parse($csv_db_name);
$csv->data[$vals['email']] = $vals;
$csv->save();
#print_r($csv->data);
$from = '"LISA Symposium Website" <rafik@physik.uzh.ch>';
$replyto = $from;
$to1 = "rafael.kueng@uzh.ch";
$to2 = "relativityUZH@gmail.com";
$subj = "[LISA] registration";
$headers = 'From: ' . $from . "\r\n";
$headers .= 'Reply-To:' . $replyto . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
$headers .= 'Delivery-Date: ' . date("r") . "\r\n";
$msg = "Someone registered for the lisa conference. Here a backup dump\r\n\r\n";
if ($vals['lookingForRoomMate']) {
$msg .= "ADD TO EMAIL LIST! : {$vals['email']} \r\n\r\n";
示例3: process
/**
* Renders the CSV.
*
* @return void
*/
public function process()
{
$params = $this->gp;
$exportParams = $this->utilityFuncs->getSingle($this->settings, 'exportParams');
if (!is_array($exportParams) && strpos($exportParams, ',') !== FALSE) {
$exportParams = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $exportParams);
}
//build data
foreach ($params as $key => &$value) {
if (is_array($value)) {
$value = implode(',', $value);
}
if (!empty($exportParams) && !in_array($key, $exportParams)) {
unset($params[$key]);
}
$value = str_replace('"', '""', $value);
}
// create new parseCSV object.
$csv = new \parseCSV();
//parseCSV expects data to be a two dimensional array
$data = array($params);
$fields = FALSE;
if (intval($this->utilityFuncs->getSingle($this->settings, 'addFieldNames')) === 1) {
$fields = array_keys($params);
$csv->heading = TRUE;
}
if ($this->settings['delimiter']) {
$csv->delimiter = $csv->output_delimiter = $this->utilityFuncs->getSingle($this->settings, 'delimiter');
}
if ($this->settings['enclosure']) {
$csv->enclosure = $this->utilityFuncs->getSingle($this->settings, 'enclosure');
}
$inputEncoding = $this->utilityFuncs->getSingle($this->settings, 'inputEncoding');
if (strlen(trim($inputEncoding)) === 0) {
$inputEncoding = 'utf-8';
}
$outputEncoding = $this->utilityFuncs->getSingle($this->settings, 'outputEncoding');
if (strlen(trim($outputEncoding)) === 0) {
$outputEncoding = 'utf-8';
}
$csv->input_encoding = strtolower($inputEncoding);
$csv->output_encoding = strtolower($outputEncoding);
$csv->convert_encoding = FALSE;
if ($csv->input_encoding !== $csv->output_encoding) {
$csv->convert_encoding = TRUE;
}
if (intval($this->settings['returnFileName']) === 1 || intval($this->settings['returnGP']) === 1) {
$outputPath = $this->utilityFuncs->getDocumentRoot();
if ($this->settings['customTempOutputPath']) {
$outputPath .= $this->settings['customTempOutputPath'];
} else {
$outputPath .= '/typo3temp/';
}
$outputPath = $this->utilityFuncs->sanitizePath($outputPath);
$filename = $outputPath . $this->settings['filePrefix'] . $this->utilityFuncs->generateHash() . '.csv';
$csv->save($filename, $data, FALSE, $fields);
if (intval($this->settings['returnFileName']) === 1) {
return $filename;
} else {
if (!is_array($this->gp['generator-csv-generated-files'])) {
$this->gp['generator-csv-generated-files'] = array();
}
$this->gp['generator-csv-generated-files'][] = $filename;
return $this->gp;
}
} else {
$fileName = 'formhandler.csv';
if ($this->settings['outputFileName']) {
$fileName = $this->utilityFuncs->getSingle($this->settings, 'outputFileName');
}
$csv->output($fileName, $data, $fields);
die;
}
}
示例4: parseCSV
$static_array[1]['Alternative Product Submissions'] = 'number';
$search_response = array_merge($static_array, $search_response);
$file_name = 'geo_alt.csv';
$file_path = ABSPATH . "uploads/" . $file_name;
$csv = new parseCSV();
@unlink($file_path);
$csv->data = $search_response;
$csv->save($file_path, $search_response);
//trace($csv->data);
}
}
if (isset($_GET['boycott']) && $_GET['boycott'] == 'yes') {
global $wpdb;
$query = "SELECT p.post_excerpt AS Country, COUNT(*) AS 'Boycott Product Submissions' \n FROM {$wpdb->posts} AS p\n WHERE p.post_type = 'banned-product'\n AND p.post_status = 'publish'\n GROUP BY p.post_excerpt";
$search_response = $wpdb->get_results($query, ARRAY_A);
if (count($search_response) > 0) {
$static_array = array();
$static_array[0]['Country'] = 'Country';
$static_array[0]['Boycott Product Submissions'] = 'Boycott Product Submissions';
$static_array[1]['Country'] = 'string';
$static_array[1]['Boycott Product Submissions'] = 'number';
$search_response = array_merge($static_array, $search_response);
$file_name = 'geo_boycott.csv';
$file_path = ABSPATH . "uploads/" . $file_name;
@unlink($file_path);
$csv = new parseCSV();
$csv->data = $search_response;
$csv->save($file_path, $search_response);
//trace($csv->data);
}
}
示例5: saveTheOutput
/**
* Saves the new converted output csv file.
* @param type $filename
* @param type $output_data
* @return \PbcMagmi
*/
function saveTheOutput($filename, $output_data)
{
if ($output_data != NULL) {
if ($output_data[0] != NULL) {
$outputCSV = new parseCSV();
$newcolumns = array_keys($output_data[0]);
$outputCSV->titles = $newcolumns;
$outputCSV->data = $output_data;
$outputCSV->save($filename, $output_data);
if ($this->config['script_verbose']) {
echo "Output file succesfully saved in : ";
printf("\n");
echo $filename . ' file.';
printf("\n");
}
return $this;
}
}
}
示例6: postbackdel
function options_panel()
{
global $wpdb;
$isedit = false;
$message = "";
$editrow = "";
if (isset($_POST['eddem']) && $_POST['eddem'] == "1") {
$editrow = "";
$isedit = false;
global $wpdb;
$nonce = $_POST['nonce-eventify'];
if (!wp_verify_nonce($nonce, 'eventify-nonce')) {
die('Security Check - If you receive this in error, log out and back in to WordPress');
}
$table_name = $wpdb->prefix . "em_main";
$sql = "update " . $table_name . " set em_date='" . $_POST['datepicker'] . "', em_time='" . $_POST['timepick_from'] . "-" . $_POST['timepick_to'] . "', em_desc='" . str_ireplace("'", "\\'", $_POST['em_desc']) . "', em_title='" . str_ireplace("'", "\\'", $_POST['em_title']) . "', em_venue='" . str_ireplace("'", "\\'", $_POST['em_venue']) . "', em_timezone='" . $_POST['em_timezone'] . "', em_timestamp='" . strtotime($_POST['datepicker']) . "' where em_id='" . $_POST['emidd'] . "';";
//echo $sql;
$wpdb->query($sql);
update_option("em_timezone", $_POST['em_timezone']);
$message = "Event Updated!";
$wpdb->print_error();
}
if (isset($_POST['eem'])) {
//show the edit event form and display the values from the db
$isedit = true;
global $wpdb;
$nonce = $_POST['nonce-eventify'];
if (!wp_verify_nonce($nonce, 'eventify-nonce')) {
die('Security Check - If you receive this in error, log out and back in to WordPress');
}
$table_name = $wpdb->prefix . "em_main";
$sqlqry = "Select * from " . $table_name . " where em_id='" . $_POST['eem'] . "'";
$editrow = $wpdb->get_results($sqlqry);
}
if (isset($_POST['addem']) && $_POST['addem'] == "1") {
$nonce = $_POST['nonce-eventify'];
if (!wp_verify_nonce($nonce, 'eventify-nonce')) {
die('Security Check - If you receive this in error, log out and back in to WordPress');
}
$message = "Event Added! :)";
//add the event to the db and the table :)
$table_name = $wpdb->prefix . "em_main";
if ($_POST['saveitaspopup'] == "posted") {
// Create post object
$my_post = array();
$my_post['post_title'] = $_POST['em_title'];
$my_post['post_content'] = "<h2>Event Description:</h2>" . $_POST['em_desc'] . "<br/><h2>Event Date</h2>" . $_POST['datepicker'] . "<br/><h2>Event Time</h2> From: " . $_POST['timepick_from'] . " - To: " . $_POST['timepick_to'] . " <br/><h2>Event Venue</h2>" . $_POST['em_venue'] . "<br/><h2>Event TimeZone</h2>" . $_POST['em_timezone'];
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array(99 => 'Events');
// Insert the post into the database
$postedid = wp_insert_post($my_post);
$sql = "insert into " . $table_name . " values(null,'" . $_POST['datepicker'] . "','" . $_POST['timepick_from'] . "-" . $_POST['timepick_to'] . " ','" . str_ireplace("'", "\\'", $_POST['em_desc']) . "','" . str_ireplace("'", "\\'", $_POST['em_title']) . "','" . str_ireplace("'", "\\'", $_POST['em_venue']) . "','" . $_POST['em_timezone'] . "','" . $postedid . "','" . strtotime($_POST['datepicker']) . "')";
} else {
$sql = "insert into " . $table_name . " values(null,'" . $_POST['datepicker'] . "','" . $_POST['timepick_from'] . "-" . $_POST['timepick_to'] . "','" . str_ireplace("'", "\\'", $_POST['em_desc']) . "','" . str_ireplace("'", "\\'", $_POST['em_title']) . "','" . str_ireplace("'", "\\'", $_POST['em_venue']) . "','" . $_POST['em_timezone'] . "','0','" . strtotime($_POST['datepicker']) . "')";
}
$wpdb->query($sql);
update_option("em_timezone", $_POST['em_timezone']);
$wpdb->print_error();
}
if (isset($_POST['delem']) && $_POST['delem'] == "1") {
if (!empty($_POST['delemid'])) {
$nonce = $_POST['nonceeventify'];
if (!wp_verify_nonce($nonce, 'eventify-nonce')) {
die('Security Check - If you receive this in error, log out and back in to WordPress');
}
//$message = "Selected Event(s) Deleted! :)";
$delidsem = implode(",", $_POST['delemid']);
//echo $delidsem;
//delete the event(s) from the db and the table :)
$table_name = $wpdb->prefix . "em_main";
$sql_qury = "delete from " . $table_name . " where em_id in (" . $delidsem . ")";
$message = "Event(s) Deleted. :)";
$wpdb->query($sql_qury);
$wpdb->print_error();
} else {
$message = "<span style='color:red;'>No events selected for deletion</span>";
}
}
/*code for backing up events*/
if (isset($_POST['backemall']) && $_POST['backemall'] == "1") {
global $wpdb;
$table_name = $wpdb->prefix . "em_main";
$qry = "select * from " . $table_name . " order by em_timestamp ASC";
$results = $wpdb->get_results($qry);
$backupfilename = "events.csv";
$backup_file_handle = fopen(WP_PLUGIN_DIR . "/eventify/uploads/" . $backupfilename, 'w') or die('Something terribly went wrong with creating the file');
require_once WP_PLUGIN_DIR . '/eventify/php/parsecsv.lib.php';
$csv = new parseCSV();
//print_r($results);
$i = 1;
$data[0] = array('title' => 'title', 'date' => 'date', 'time' => 'time', 'desc' => 'desc', 'venue' => 'venue', 'timezone' => 'timezone');
foreach ($results as $row) {
$data[$i] = array('title' => $row->em_title, 'date' => $row->em_date, 'timefromtimeto' => $row->em_time, 'desc' => $row->em_desc, 'venue' => $row->em_venue, 'timezone' => $row->em_timezone);
$i++;
}
$csv->save(WP_PLUGIN_DIR . "/eventify/uploads/" . $backupfilename, $data, true);
fclose($backup_file_handle);
$message = "Events backup complete. <a href=\"" . WP_PLUGIN_URL . "/eventify/uploads/" . $backupfilename . "\">Save file</a> by right click->save as. Save the file as .csv file";
}
//.........这里部分代码省略.........
示例7: parseCSV
<?php
ini_set('display_errors', '1');
require_once 'parsecsv.lib.php';
$csv = new parseCSV();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$pages = json_decode($_POST['pages']);
$filename = json_decode($_POST['filename']);
$sorted_pages = [];
$lnth = sizeof($pages);
$filepath = '../data/' . $filename . '.csv';
if (!file_exists($filepath)) {
$csv->save($filepath, array(array('ID', 'Name', 'Likes', 'Category', 'Website', 'Email', 'Page Url')), true);
}
for ($i = 0; $i < $lnth; $i++) {
$innerArray = [];
$innerArray['id'] = $pages[$i]->{'id'};
$innerArray['name'] = $pages[$i]->{'name'};
$innerArray['likes'] = $pages[$i]->{'likes'};
$innerArray['category'] = $pages[$i]->{'category'};
$innerArray['website'] = $pages[$i]->{'website'};
$innerArray['email'] = $pages[$i]->{'emails'}[0];
$innerArray['link'] = $pages[$i]->{'link'};
$sorted_pages[] = $innerArray;
}
$csv->save($filepath, $sorted_pages, true);
echo 'true';
}
?>
示例8: parseCSV
}
$csv = new parseCSV();
$csv->delimiter = ';';
$csv->parse('dados.csv');
$csvData = $csv->data;
foreach ($csvData as $data_key => $data_value) {
if ($data_value['curso'] == $curso) {
unset($csvData[$data_key]);
}
}
unset($csv);
$csv = new File('dados.csv', 'w');
$csv->write_file('matricula;email;nome;curso;turma' . PHP_EOL);
unset($csv);
$csv = new parseCSV();
$csv->delimiter = ';';
$csv->save('dados.csv', $csvData, true);
unset($csv);
$csv = new parseCSV();
$csv->delimiter = ';';
$csv->fields = array('matricula', 'email', 'nome', 'curso', 'turma');
$csv->parse('dados.csv');
} elseif (isset($_POST['curso_select'])) {
$array = [];
foreach (Courses::return_specific_course_class($_POST['curso_select']) as $turma) {
$array[] = $turma;
}
echo json_encode($array);
} else {
header('location: index.php');
}
示例9: saveCSV
public function saveCSV($inData)
{
$csvData = array('error' => "File Not Found");
$user_file_dir = $this->session->get_user_var('file_directory');
$userID = $this->session->get_user_var('id');
$basePath = "../user_files/" . $user_file_dir . "/datasources/";
$realBasePath = realpath($basePath);
$userPath = $basePath . $inData['subdir'] . $inData['file'];
$realUserPath = realpath($userPath);
$dataOut = array();
$returnResults = array();
if ($realUserPath === false || strpos($realUserPath, $realBasePath) !== 0) {
//Is directory Traversal, bad!
$this->outData['data'] = $csvData;
} else {
//Not directory Traversal.
$csv = new parseCSV();
$data = stripslashes(html_entity_decode($inData['data']));
$data = json_decode($data);
$csv->save($realUserPath, $data, false, array());
$sqlDir = "/datasources/server/user_files/" . $user_file_dir . "/datasources/" . $inData['subdir'];
//Flag the curl request as processed/deleted.
$query = "SELECT id from datasources WHERE user_id = ? and data_path = ? and file_name = ?";
$stmt = $this->sql->link->prepare($query);
$stmt->bind_param('iss', $userID, $sqlDir, $inData['file']);
$stmt->execute();
$stmt->store_result();
stmt_bind_assoc($stmt, $returnResults);
// loop through all result rows
while ($stmt->fetch()) {
foreach ($returnResults as $key => $value) {
$row_tmb[$key] = $value;
}
$dataOut = $row_tmb;
}
$lineCount = count($data) - 1;
if ($lineCount < 0) {
$lineCount = 0;
}
$headers = json_encode(array_filter($data[0]));
$query = "UPDATE datasources SET `headers` = ?, `lines` = ? WHERE `id` = ?";
$stmt = $this->sql->link->prepare($query);
$stmt->bind_param('sii', $headers, $lineCount, $dataOut['id']);
$stmt->execute();
$this->outData['success'] = 1;
}
echo json_encode($this->outData);
}
示例10: UploadImg
$uf = new UploadImg();
if (isset($_POST['form-button'])) {
// TODO: chamar classe CSV, retornando um array com todas as matrículas
$csv = new parseCSV();
$csv->delimiter = ';';
$csv->parse('dados.csv');
$csvData = $csv->data;
$matriculas = [];
foreach ($csvData as $data) {
$matriculas[] = $data['matricula'];
}
if (!in_array($_POST['form-matricula'], $matriculas)) {
$uf->setFileImg($_FILES['form-imagem']);
if ($uf->checkImgExtension()) {
echo '<div class="alert alert-success" role="alert"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> Imagem enviada!</div>';
$form_ops->save('dados.csv', array(array($_POST['form-matricula'], $_POST['form-email'], $_POST['form-name'], $_POST['form-curso'], $_POST['form-turma'])), true);
$uf->upload_img($_FILES['form-imagem'], $_POST['form-curso'], $_POST['form-turma'], $_POST['form-matricula'], $uf->getImgExtension());
} else {
echo '<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> A imagem não está no formato correto! Por favor, faça upload de uma imagem em PNG, JPG ou JPEG.</div>';
}
} else {
echo '<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> Já existe um cadastro com essa matrícula :(</div>';
}
}
?>
<form class="form-horizontal" role="form" id="formulario" method="post" action="index.php" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label col-sm-2" for="form-name">Nome:</label>
<div class="col-sm-10">
<input type="text" name="form-name" class="form-control" id="form-name" aria-required="true" required="true">
</div>
示例11: parseCSV
# include parseCSV class.
require_once '../parsecsv.lib.php';
# create new parseCSV object.
$csv = new parseCSV();
# Example conditions:
// $csv->conditions = 'title contains paperback OR title contains hardcover';
// $csv->conditions = 'author does not contain dan brown';
// $csv->conditions = 'rating < 4 OR author is John Twelve Hawks';
// $csv->conditions = 'rating > 4 AND author is Dan Brown';
$data = stripslashes($_POST['data']);
$data = json_decode($data);
$titles = stripslashes($_POST['titles']);
$titles = json_decode($titles);
echo "<pre>";
//$array = array('firstname' => 'John', 'lastname' => 'Doe', 'email' => 'john@doe.com');
//$csv->parse('_books.csv', 0 , 1000); // At max 1000 lines.
print_r($data);
//$csv->output (true, 'movies.csv', $array);
//$array);
//$csv->output (true, 'data.csv', $data);
//$outdata = $csv->unparse($data, $titles, true, null, ',');
$csv->save('../out/test.csv', $data, false, array());
?>
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round($finish - $start, 4);
echo 'Page generated in ' . $total_time . ' seconds.';