本文整理汇总了PHP中parseCSV::auto方法的典型用法代码示例。如果您正苦于以下问题:PHP parseCSV::auto方法的具体用法?PHP parseCSV::auto怎么用?PHP parseCSV::auto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parseCSV
的用法示例。
在下文中一共展示了parseCSV::auto方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: csvDataToMemcache
function csvDataToMemcache($csvList, $csvDir, $memIP, $memPort)
{
$memcached = new Memcache();
$memcached->connect($memIP, $memPort);
foreach ($csvList as $key => $value) {
$csvObj = new parseCSV();
$csvObj->auto($csvDir . '/' . $value);
list($fileName, $fileType) = explode('.', $value);
$memcached->set($fileName, $csvObj->data, MEMCACHE_COMPRESSED, 0);
//debug info
//echo "<br/>--------------------------------------------$fileName.csv to memcache-------------------------------------------<br/>";
print_r($memcached->get($fileName));
}
$memcached->close();
echo "success";
}
示例2: getCSV
public static function getCSV($file_path, $limit = false, $offset = false)
{
if (file_exists($file_path) && is_readable($file_path)) {
if (!class_exists('parseCSV')) {
require_once GMEMBER_DIR . '/assets/libs/parsecsv-for-php/parsecsv.lib.php';
}
$csv = new parseCSV();
$csv->encoding('UTF-16', 'UTF-8');
if ($offset) {
$csv->offset = $offset;
}
if ($limit) {
$csv->limit = $limit;
}
$csv->auto($file_path);
return array('titles' => $csv->titles, 'data' => $csv->data);
}
return false;
return array('titles' => array(), 'data' => array());
}
示例3: index
function index()
{
if (!empty($this->data) && !empty($_POST['submit'])) {
$string = explode(",", trim($this->data['InventoryMaster']['all_item']));
$prsku = $string[0];
if (!empty($string[1])) {
$prname = $string[1];
}
if (!empty($prsku) && !empty($prname)) {
$conditions = array('InventoryMaster.category LIKE' => '%' . $prname . '%', 'InventoryMaster.category LIKE' => '%' . $prsku . '%');
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'InventoryMaster.id ASC', 'conditions' => $conditions);
}
if (!empty($prsku)) {
$conditions = array('OR' => array('InventoryMaster.product_code LIKE' => "%{$prsku}%", 'InventoryMaster.category LIKE' => "%{$prsku}%"));
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'InventoryMaster.id ASC', 'conditions' => $conditions);
}
$this->InventoryMaster->recursive = 1;
$this->set('inventorymasters', $this->paginate());
} else {
if (!empty($_POST['checkid']) && !empty($_POST['exports'])) {
// echo 'dfbgghbfg';die();
$checkboxid = $_POST['checkid'];
App::import("Vendor", "parsecsv");
$csv = new parseCSV();
$filepath = "C:\\Users\\Administrator\\Downloads" . "inventorymasterdb.csv";
$csv->auto($filepath);
$this->set('inventorymasters', $this->InventoryMaster->find('all', array('conditions' => array('InventoryMaster.id' => $checkboxid))));
$this->layout = null;
$this->autoLayout = false;
Configure::write('debug', '2');
} else {
$this->InventoryMaster->recursive = 1;
//$users = $this->InventoryMaster->User->find('list');
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'InventoryMaster.id ASC');
$this->set('inventorymasters', $this->paginate());
}
}
}
示例4: csvFileread
function csvFileread($target_file)
{
# include parseCSV class.
require_once 'parsecsv.lib.php';
# create new parseCSV object.
$csv = new parseCSV();
# Parse '_books.csv' using automatic delimiter detection...
$csv->auto("uploads/{$target_file}.csv");
//$csv->auto("abc.csv");
# ...or if you know the delimiter, set the delimiter character
# if its not the default comma...
$csv->delimiter = "\t";
# tab delimited
# ...and then use the parse() function.
// $csv->parse('_books.csv');
# Output result.
echo "hello";
print_r($csv->data);
$i = 0;
foreach ($csv->data as $key => $row) {
print_r($row);
if ($i == 5) {
die;
}
$i++;
}
}
示例5: index
function index()
{
if (!empty($this->data) && !empty($_POST['submit'])) {
$string = explode(",", trim($this->data['EbayenglishListing']['all_item']));
$prsku = $string[0];
if (!empty($string[1])) {
$prname = $string[1];
}
if (!empty($prsku) && !empty($prname)) {
$conditions = array('EbayenglishListing.title LIKE' => '%' . $prname . '%', 'EbayenglishListing.title LIKE' => '%' . $prsku . '%');
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'EbayenglishListing.sku id', 'conditions' => $conditions);
}
if (!empty($prsku)) {
$conditions = array('OR' => array('EbayenglishListing.title LIKE' => "%{$prsku}%", 'EbayenglishListing.sku LIKE' => "%{$prsku}%"));
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'EbayenglishListing.id ASC', 'conditions' => $conditions);
}
$this->set('ebayenglishlistings', $this->paginate());
} else {
if (!empty($_POST['checkid']) && !empty($_POST['exports'])) {
$checkboxid = $_POST['checkid'];
App::import("Vendor", "parsecsv");
$csv = new parseCSV();
$filepath = "C:\\Users\\Administrator\\Downloads" . "ebayenglishlistings.csv";
$csv->auto($filepath);
$this->set('ebayenglishlistings', $this->EbayenglishListing->find('all', array('conditions' => array('EbayenglishListing.id' => $checkboxid))));
$this->layout = null;
$this->autoLayout = false;
Configure::write('debug', '2');
} else {
$this->EbayenglishListing->recursive = 1;
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'EbayenglishListing.id ASC');
$this->set('ebayenglishlistings', $this->paginate());
}
}
}
示例6: upload
public function upload()
{
ini_set("auto_detect_line_endings", true);
ini_set('memory_limit', '512M');
set_time_limit(600);
require_once ROOT . DS . 'vendor' . DS . 'parsecsv.lib.php';
try {
$numberListTable = TableRegistry::get('NumberLists');
$numberTable = TableRegistry::get('Numbers');
// Generate temp file name
$uploadFullPath = TMP . DS . Text::uuid();
// Move file to temp location
if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadFullPath)) {
throw new \Exception('Cannot copy file to tmp location');
}
$dateTimeUtc = new \DateTimeZone('UTC');
$now = new \DateTime('now', $dateTimeUtc);
// Create new list
$newNumberListData = ['list_name' => $this->request->data['list_name'], 'list_description' => $this->request->data['list_description'], 'create_datetime' => $now, 'update_datetime' => $now];
$numberList = $numberListTable->newEntity($newNumberListData);
$numberListTable->save($numberList);
// Get the data from the file
$csv = new \parseCSV();
$csv->heading = false;
$csv->auto($uploadFullPath);
if (count($csv->data) == 0) {
throw new \Exception('File is empty');
}
$newNumberData = [];
foreach ($csv->data as $row) {
$responseM360 = $this->M360->optInTfn($row[1]);
// $response['d'][] = $responseM360;
$newNumberData = ['number_list_id' => $numberList->number_list_id, 'country_code' => $row[0], 'phone_number' => $row[1], 'opt_in_tfn' => (bool) $responseM360['Message360']['OptIns']['OptIn']['Status'] === 'updated', 'add_datetime' => $now];
$number = $numberTable->newEntity($newNumberData);
$numberTable->save($number);
}
// $numbers = $numberTable->newEntity($newNumberData);
//
// $numberTable->connection()->transactional(function () use ($numberTable, $numbers) {
// foreach ($numbers as $number) {
// $numberTable->save($number, ['atomic' => false]);
// }
// });
unlink($uploadFullPath);
$response['i'] = $newNumberData;
$response['status'] = 1;
} catch (\Excaption $ex) {
$response['status'] = 0;
$response['message'] = $ex->getMessage();
}
$this->set(compact('response'));
$this->set('_serialize', ['response']);
}
示例7: saveimport
public function saveimport()
{
$response = array("status" => 0, "msg" => "Gagal simpan data");
include APPPATH . "libraries/parsecsv.lib.php";
// echo "<pre>";
// print_r($_FILES);
// echo "</pre>";
if (isset($_FILES['inputFile']) && !empty($_FILES['inputFile']['name'])) {
$files = $_FILES['inputFile'];
$allowed_extension = array('csv');
$extension = end(explode('.', strtolower($files['name'])));
if (in_array($extension, $allowed_extension)) {
$newname = date('YmdHis') . "_import_cpns.csv";
if (move_uploaded_file($files['tmp_name'], _ROOT . "files/import/{$newname}")) {
if (file_exists(_ROOT . "files/import/{$newname}")) {
$response = array("status" => 0, "msg" => "sukses simpan data");
$destination = _ROOT . "files/import/{$newname}";
$csv = new parseCSV();
$data = $csv->auto($destination);
$datashipping = array();
foreach ((array) $csv->data as $index => $row) {
$save = $this->pengadaan_model->simpanDataCPNSimport($row);
}
$response = array("status" => 1, "msg" => "Sukses import file");
}
}
} else {
$response = array("status" => 0, "msg" => "Ekstensi file harus .csv");
}
}
// echo "<pre>";
// print_r($response);
// echo "</pre>";
echo json_encode($response);
exit;
}
示例8: array
<?php
require_once 'parsecsv.lib.php';
require_once 'Excel/reader.php';
session_start();
include 'inc.db.php';
$active_user = $_SESSION['user_id'];
if (isset($_POST['upfile']) && $_POST['upfile'] != "") {
$allowedExts = array("csv", "xls");
$temp = explode(".", $_POST['upfile']);
$extension = end($temp);
if ($extension == "csv") {
$csv = new parseCSV();
$csv->auto('uploads/' . $_POST['upfile']);
foreach ($csv->data as $key => $row) {
$asin = $row['asin'];
$res = mysql_query("select * from asins_table where asins='" . $asin . "' and UserID=" . $active_user . "");
if (!mysql_num_rows($res)) {
mysql_query("INSERT INTO asins_table(asins,UserID,processed,provider) values('" . $asin . "'," . $active_user . ",0,'Amazon')");
}
}
} else {
if ($extension == "xls") {
$data = new Spreadsheet_Excel_Reader();
//$data->setOutputEncoding('CP1251');
$data->read('uploads/' . $_POST['upfile']);
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$asin = rawurlencode($data->sheets[0]['cells'][$i][1]);
$res = mysql_query("select * from asins_table where asins='" . $asin . "' and UserID=" . $active_user . "");
if (!mysql_num_rows($res)) {
mysql_query("INSERT INTO asins_table(asins,UserID,processed,provider) values('" . $asin . "'," . $active_user . ",0,'Amazon')");
示例9: download
function download()
{
App::import("Vendor", "parsecsv");
$csv = new parseCSV();
$filepath = "C:\\Users\\Administrator\\Downloads" . "projects.csv";
$csv->auto($filepath);
$this->set('projects', $this->Listing->find('all'));
$this->layout = null;
$this->autoLayout = false;
Configure::write('App.encoding', 'utf8_unicode_ci');
Configure::write('debug', '0');
}
示例10: array
/**
* import_gradebook_screen( $vars )
*
* Hooks into screen_handler
* Imports a CSV file data into the gradebook_screen(). It doesn't save anything!
*
* @param Array $vars a set of variables received for this screen template
* @return Array $vars a set of variable passed to this screen template
*/
function import_gradebook_screen($vars)
{
$is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], 'gradebook_import_nonce');
if (!$is_nonce) {
$vars['die'] = __('BuddyPress Courseware Nonce Error while importing gradebook.', 'bpsp');
return $this->gradebook_screen($vars);
}
$grades = array();
if (isset($_FILES['csv_filename']) && !empty($_FILES['csv_filename'])) {
require_once 'parseCSV.class.php';
// Load CSV parser
$csv = new parseCSV();
$csv->auto($_FILES['csv_filename']['tmp_name']);
foreach ($csv->data as $grade) {
$id = bp_core_get_userid_from_nicename($grade['uid']);
if ($id) {
$grades[$id] = $grade;
}
}
if (count($csv->data) == count($grades)) {
$vars['message'] = __('Data imported successfully, but it is not saved yet! Save this form changes to keep the data.', 'bpsp');
} else {
$vars['error'] = __('File data contains error or entries from other gradebook. Please check again.', 'bpsp');
}
}
$vars['grades'] = $grades;
$vars['assignment_permalink'] = $vars['assignment_permalink'] . '/gradebook';
unset($_POST);
return $this->gradebook_screen($vars);
}
示例11: actionUpload
public function actionUpload()
{
// $assetPrefix = Yii::$app->assetManager->publish(dirname(__FILE__) . '/../assets', array('forceCopy' => true));
// Yii::$app->clientScript->registerScriptFile($assetPrefix . '/md5.min.js');
// Yii::$app->clientScript->registerScriptFile($assetPrefix . '/jdenticon-1.3.0.min.js');
require_once dirname(__FILE__) . "/../lib/parsecsv.lib.php";
$csv = new \parseCSV();
$model = new BulkImportForm();
$validImports = array();
$invalidImports = array();
if (isset($_POST['BulkImportForm'])) {
$model->attributes = $_POST['BulkImportForm'];
if (!empty($_FILES['BulkImportForm']['tmp_name']['csv_file'])) {
$file = \yii\web\UploadedFile::getInstance($model, 'csv_file');
$group_id = 1;
$csv->auto($file->tempName);
foreach ($csv->data as $data) {
// Make a username from the first and last names if username is mising
if (empty($data['username'])) {
// $data['username'] = substr(str_replace(" ", "_", strtolower(trim($data['firstname']) . "_" . trim($data['lastname']))), 0, 25);
$data['username'] = substr(ucfirst(trim($data['firstname'])) . " " . ucfirst(trim($data['lastname'])), 0, 25);
}
// Put data into correct format
$importData = array('username' => $data['username'], 'password' => $data['password'], 'firstname' => $data['firstname'], 'lastname' => $data['lastname'], 'email' => $data['email'], 'space_names' => explode(",", $data['space_names']), 'group_id' => $group_id);
// Register user
if ($this->registerUser($importData)) {
$validImports[] = $importData;
} else {
$invalidImports[] = $importData;
}
}
}
}
return $this->render('import_complete', array('validImports' => $validImports, 'invalidImports' => $invalidImports));
}
示例12: importProductsMap
public function importProductsMap()
{
$file = Input::file('file');
if ($file == null) {
Session::flash('error', 'Debe seleccionar un archivo');
return Redirect::to('importar/productos');
}
$name = $file->getRealPath();
require_once app_path() . '/includes/parsecsv.lib.php';
$csv = new parseCSV();
$csv->heading = false;
$csv->encoding('ISO-8859-1', 'UTF-8');
$csv->auto($name);
Session::put('data', $csv->data);
$headers = true;
$hasHeaders = true;
$mapped = array();
$columns = array('', Product::$fieldProductKey, Product::$fieldNotes, Product::$fieldCost);
if (count($csv->data) > 0) {
$headers = $csv->data[0];
for ($i = 0; $i < count($headers); $i++) {
$title = strtolower($headers[$i]);
$mapped[$i] = '';
$map = array('Nombre' => Product::$fieldProductKey, 'Razón Social' => Product::$fieldNotes, 'Nit' => Product::$fieldCost);
foreach ($map as $search => $column) {
foreach (explode("|", $search) as $string) {
if (strpos($title, 'sec') === 0) {
continue;
}
if (strpos($title, $string) !== false) {
$mapped[$i] = $column;
break 2;
}
}
}
}
}
$data = array('data' => $csv->data, 'headers' => $headers, 'hasHeaders' => $hasHeaders, 'columns' => $columns, 'mapped' => $mapped, 'categories' => Category::where('account_id', '=', Auth::user()->account_id)->orderBy('id')->get());
return View::make('importar.import_products_map', $data);
}
示例13: parseCSV
<pre>
<?php
# include parseCSV class.
require_once '../parsecsv.lib.php';
# create new parseCSV object.
$csv = new parseCSV();
# Parse '_books.csv' using automatic delimiter detection...
$csv->auto('PercFramesLoadedonQA_092915.csv');
# ...or if you know the delimiter, set the delimiter character
# if its not the default comma...
// $csv->delimiter = "\t"; # tab delimited
# ...and then use the parse() function.
// $csv->parse('_books.csv');
# Output result.
//echo '<pre>';print_r($csv->data);die;
$i = 1;
//$j=2;
$html = '';
$aFPC = array();
foreach ($csv->data as $key => $row) {
$aFPC[] = $row['FPC Code'];
//$html .= '<LineItem Id="'.$i.'" Quantity="'.$i.'"><FPC Value="'.$row["FPC"].'"/><Patient FirstName="New"'.$i.' LastName="Order"'.$i.' PatientId="'.$j.'"/></LineItem>';
//echo $result;
//$i++;
//$j++;
}
//echo '<pre>';print_r(array_unique($aFPC));die;
foreach (array_unique($aFPC) as $key => $row) {
//$html = ( htmlentities('<LineItem Id="'.$i.'" Quantity="'.$i.'"><FPC Value="'.$row.'"/><Patient FirstName="New"'.$i.' LastName="Order"'.$i.' PatientId="'.$j.'"/></LineItem>'));
$html .= '<LineItem Id="' . $i . '" Quantity="' . $i . '"><FPC Value="' . $row . '"/><Patient FirstName="New' . $i . '" LastName="Order' . $i . '" PatientId="' . $i . '"/></LineItem>';
$i++;
示例14: mapFile
public function mapFile($entityType, $filename, $columns, $map)
{
require_once app_path() . '/Includes/parsecsv.lib.php';
$csv = new parseCSV();
$csv->heading = false;
$csv->auto($filename);
Session::put("{$entityType}-data", $csv->data);
$headers = false;
$hasHeaders = false;
$mapped = array();
if (count($csv->data) > 0) {
$headers = $csv->data[0];
foreach ($headers as $title) {
if (strpos(strtolower($title), 'name') > 0) {
$hasHeaders = true;
break;
}
}
for ($i = 0; $i < count($headers); $i++) {
$title = strtolower($headers[$i]);
$mapped[$i] = '';
if ($hasHeaders) {
foreach ($map as $search => $column) {
if ($this->checkForMatch($title, $search)) {
$mapped[$i] = $column;
break;
}
}
}
}
}
$data = array('entityType' => $entityType, 'data' => $csv->data, 'headers' => $headers, 'hasHeaders' => $hasHeaders, 'columns' => $columns, 'mapped' => $mapped);
return $data;
}
示例15: csvFileread
function csvFileread($target_file)
{
# include parseCSV class.
require_once 'parsecsv.lib.php';
$conn = mysql_connect("localhost", "root", "proggasoft123") or die("unable to connect localhost" . mysql_error());
$db = mysql_select_db("testfile", $conn) or die("unable to select db name");
# create new parseCSV object.
$csv = new parseCSV();
# Parse '_books.csv' using automatic delimiter detection...
$csv->auto("uploads/{$target_file}.csv");
//$csv->auto("abc.csv");
# ...or if you know the delimiter, set the delimiter character
# if its not the default comma...
$csv->delimiter = "\t";
# tab delimited
# ...and then use the parse() function.
// $csv->parse('_books.csv');
# Output result.
// print_r($csv->data);
$i = 0;
foreach ($csv->data as $key => $row) {
//print_r($row);
//if ($i == 5)
//die();
//Work on Main category...........
$main_category = mysql_real_escape_string($row['Categories']);
$maincatesql = "INSERT INTO main_catagories (main_catagory) values ('" . $main_category . "')";
//echo $catesql;
$result = mysql_query($maincatesql);
if ($result) {
//$main_cat_id = "query of last id";
$main_cat_id = mysql_insert_id();
} else {
die('not successfuly');
}
//Work on Category...........
$category = mysql_real_escape_string($row['Mypafway Categories']);
$catesql = "INSERT INTO categories (main_cat_id,title) values ('" . $main_cat_id . "','" . $category . "')";
$result = mysql_query($catesql);
if ($result) {
//$cat_id = "query of last id";
$cat_id = mysql_insert_id();
} else {
die('not successfuly');
}
//Work on Subcategory...........
$subcategory = mysql_real_escape_string($row['Mypafway Sub Categories']);
$subcatesql = "INSERT INTO sub_categories (main_cat_id,cat_id,title) values ('" . $main_cat_id . "','" . $cat_id . "','" . $subcategory . "')";
$subcatresult = mysql_query($subcatesql);
if ($subcatresult) {
//$cat_id = "query of last id";
$subcat_id = mysql_insert_id();
} else {
die('not successfuly');
}
//Work on Make table...........
$make = mysql_real_escape_string($row['Make']);
$makesql = "INSERT INTO auto_makes (text) values ('" . $make . "')";
$makeresult = mysql_query($makesql);
if ($makeresult) {
//$cat_id = "query of last id";
$make_id = mysql_insert_id();
} else {
die('not successfuly make');
}
//Work on Model table...........
$model = mysql_real_escape_string($row['Model']);
$modelsql = "INSERT INTO auto_models (auto_make_id,text,year,Cylinders,Engine_Code,Engine_Bore,Engine_Size,Comments_on_file) \n values ('" . $make_id . "','" . $model . "','','','','','','')";
$modelresult = mysql_query($modelsql);
if ($modelresult) {
//$cat_id = "query of last id";
$model_id = mysql_insert_id();
} else {
die('not successfuly model');
}
//Work on Product...........
$product_name = mysql_real_escape_string($row['Name']);
//echo $product_make = $row['Make'];
//echo $product_model = $row['Model'];
$product_yaer = mysql_real_escape_string($row['Year']);
$product_price = mysql_real_escape_string($row['Price']);
$product_image = mysql_real_escape_string($row['Images']);
//echo $product_desc = $row['Short Description'];
$product_desc = mysql_real_escape_string($row['Long Description']);
$product_metatitle = mysql_real_escape_string($row['Meta Title']);
$product_metadesc = mysql_real_escape_string($row['Meta Description']);
$product_tags = mysql_real_escape_string($row['Tags']);
// echo $product ="INSERT INTO products (name,company,description,price,categories,subcategories,picture,year,make,model)
// values ('".$product_name."', 'mypafway', '".$product_desc."','".$product_price."','".$cat_id."','".$subcat_id."','".$product_image."','".$product_yaer."','".$product_make."','".$product_model."')";
$product = "INSERT INTO products (user_id,title,partno,company,url,description,price,\n product_type,Quantity,headings,categories,subcategories,show_address,show_phone,show_cell,show_fax,\n picture,year,make,model,location,time,supp1,supp2,supp3,supp4,supp5,search_count,pushed,downloads,\n meta_title,meta_description,tags)\n \n values ('','" . $product_name . "','','','','{$product_desc}','" . $product_price . "','','','','" . $cat_id . "','" . $subcat_id . "',\n 'a','a','a','a','" . $product_image . "','" . $product_yaer . "','" . $make_id . "',\n '" . $model_id . "','','','','','','','','','','','" . $product_metatitle . "','" . $product_metadesc . "','" . $product_tags . "')";
$productresult = mysql_query($product);
if ($productresult) {
//$cat_id = "query of last id";
$subcat_id = mysql_insert_id();
} else {
die('not successfuly product');
}
//Work on Search keyword table...........
$searchkey = $row['Meta Keywords'];
$searchkeysql = "INSERT INTO search (date,keyword) values ('','" . $searchkey . "')";
//.........这里部分代码省略.........