function main() { $archivo = 'csvDelitos.csv'; if ($_POST["action"] == "upload") { if (copy($_FILES['archivo']['tmp_name'], "files/txt/" . $archivo)) { $status = "Archivo subido: <b>" . $archivo . "</b>"; $bStatus = True; } else { $status = "Error al subir el archivo"; } } $listaValores = readCSV($archivo); $_SESSION['fecha'] = $listaValores[0]; //array $_SESSION['valores'] = $listaValores[1]; //array $fileFechas = createFile('fechas', $listaValores[0]); //creamos archivo de fechas $fileValores = createFile('valores', $listaValores[1]); //creamos archivo de valores //echo '<br/>'.implodeFecha(); //echo '<br/>'.implodeValores(); //echo '<br/>'.countValores(); //echo '<br/>'.callPython($fileValores); //echo '<br/>'.callNormalizar($fileValores); $_SESSION['normalizar'] = callNormalizar($fileValores); //String unlink('files/txt/' . $archivo); //eliminamos el archivo creado createCSV($archivo, $listaValores[2]); }
function showOtherData() { global $db; $type = getFromSessionParams('type'); if ($type != '') { $filename = '_' . date('YmdHis'); $query = ''; switch ($type) { case 1: $filename = 'households' . $filename; $query = 'select primkey,urid,puid,status,ts from ' . dbConfig::dbSurvey() . '_households where test = 0 order by primkey'; break; case 2: $filename = 'respondents' . $filename; $query = 'select primkey,hhid,urid,status,selected,present,hhhead,finr,famr,permanent,validation,ts from ' . dbConfig::dbSurvey() . '_respondents where test = 0 order by primkey'; break; case 3: $filename = 'contacts' . $filename; $query = 'select primkey,code,contactts,proxy,urid, aes_decrypt(remark, "' . Config::smsContactRemarkKey() . '") as remark, ts from ' . dbConfig::dbSurvey() . '_contacts where primkey not like "999%"'; break; case 4: $filename = 'remarks' . $filename; $query = 'select primkey,urid, aes_decrypt(remark, "' . Config::smsRemarkKey() . '") as remark, ts from ' . dbConfig::dbSurvey() . '_remarks where primkey not like "999%"'; break; } if ($query != '') { $result = $db->selectQuery($query); createCSV($result, $filename); } } }
function mainExecute() { //support variables for logic $matches = []; $alt_dom = ''; $i = 0; $memeIDCounter = 1; $page_count = 50; $csvFileName = 'mogmaster.csv'; $toCSV = true; //array for offline pages testing // $offlinePages = ['staticpages/Slender Man _ Know Your Meme.html','staticpages/Forever Alone _ Know Your Meme.html', 'staticpages/Zerg Rush _ Know Your Meme.html']; //Regexes for matching values from extractions $rgx_src = '/data-src="(.*)" src/'; //image url $rgx_title = '/title="(.*)"/'; //Meme title $rgx_pg_href = '/href="(.*)">/'; //url for meme's page $rgx_faves = '/>(.*)</'; //favorites count $rgx_views = '/>(.*)</'; //View count $rgx_origin = '/>(.*)</'; //Origin $rgx_org_year = ''; $rgx_nsfw = '/>NSFW</'; //utility variables specifying desired Dom content selectors for extractContent function $meme_img_path = '.entry_list .photo img'; $meme_url_path = '.entry_list h2 > a'; $meme_faves_path = '.num'; $meme_views_path = 'dd.views a'; $meme_origin_path = 'dd.entry_origin_link'; $meme_nsfw_path = 'span.label-nsfw'; //Variables to store scraped content $meme_name = ''; $meme_img_url = ''; // $meme_localPath = ''; $meme_faves = null; $meme_views = null; $meme_origin = null; $meme_year = null; $meme_learn_more = ''; //Recreate CSV file createCSV($csvFileName); //main work loop while ($i <= $page_count) { //counter for tracking meme url index in $meme_href $j = 0; //counter used for offline pages array index // $m = 0; //pull and store scraped dom $html = getDOM('http://knowyourmeme.com/memes/popular/page/' . ($i + 1)); delay(); //These arrays should refer to the same memes on the same indexes //extracts array used for meme images and titles $img_content = extractContent($html, $meme_img_path); //extracts array used for meme url to access additional content $meme_href = extractContent($html, $meme_url_path); foreach ($img_content as $curr) { //check if meme is NSFW $meme_nsfw = extractContent($curr, $meme_nsfw_path); if (!empty($meme_nsfw)) { $active = 0; } else { $active = 1; } echo "Meme NSFW: {$active}" . PHP_EOL; // //save meme name $meme_name = getValue($curr, $rgx_title, false, ''); preg_match($rgx_title, $curr, $matches); $meme_name = $matches[1]; echo "Meme Name: " . $meme_name . PHP_EOL; //save meme img url $meme_img_url = getValue($curr, $rgx_src, false, ''); preg_match($rgx_src, $curr, $matches); $meme_img_url = $matches[1]; echo "Meme IMG URL: " . $meme_img_url . PHP_EOL; //get href for current meme in $curr and set variable preg_match($rgx_pg_href, $meme_href[$j], $matches); $meme_learn_more = "http://knowyourmeme.com" . $matches[1]; echo "Meme Main URL: " . $meme_learn_more . PHP_EOL; //Get DOM for current selected meme to scrape additional content //for offline testing $alt_dom = getDOM("http://knowyourmeme.com" . $matches[1]); delay(); // $alt_dom = getDOM($offlinePages[$m]); //extract favorite count $meme_faves = getValue($alt_dom, $rgx_faves, true, $meme_faves_path); $fave_segment = extractContent($alt_dom, $meme_faves_path); preg_match($rgx_faves, $fave_segment[0], $matches); $meme_faves = $matches[1]; echo "Meme Favorite Count: " . $meme_faves . PHP_EOL; //extract view count $view_segment = extractContent($alt_dom, $meme_views_path); preg_match($rgx_views, $view_segment[0], $matches); $meme_views = $matches[1]; echo "Meme Views: " . $meme_views . PHP_EOL; //Save image file to local path and collect path for saving saveImg($meme_img_url, $memeIDCounter); $memeIDCounter++; // //extract meme origin // $origin_segment = extractContent($alt_dom, $meme_origin_path); // preg_match($rgx_origin, $origin_segment[0], $matches); // $meme_origin = $matches[1]; // echo "Meme Origin: " . $meme_origin . "<br>"; echo PHP_EOL; //create Mog object and call save method $mog = new Mog($meme_name, $meme_img_url, $meme_views, $meme_faves, $meme_learn_more, $active); if ($toCSV) { $mog->saveToCSV($csvFileName); } else { $mog->saveToDB(); } echo "Total Memes Scraped: {$memeIDCounter}" . PHP_EOL; // $m++; $j++; } echo 'Page ' . ($i + 1) . 'Done...' . PHP_EOL; echo PHP_EOL; $i++; sleep(rand(15, 60)); } echo "all pages done!" . PHP_EOL; }
<?php require "auth.php"; $res = mysql_query("SELECT\n\t\t\t\t\t\t`wt_{$glob_year}_id` id,\n\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t`midname`,\n\t\t\t\t\t\t`lastname`,\n\t\t\t\t\t\t`initials`,\n\t\t\t\t\t\t`email`,\n\t\t\t\t\t\t`birthdate`,\n\t\t\t\t\t\t`phone_m`,\n\t\t\t\t\t\t`address`,\n\t\t\t\t\t\t`town`,\n\t\t\t\t\t\t`country`,\n\t\t\t\t\t\t`passport`,\n\t\t\t\t\t\t`passport_date`,\n\t\t\t\t\t\t`passport_place`,\n\t\t\t\t\t\t`passport_expire`,\n\t\t\t\t\t\t`eng`,\n\t\t\t\t\t\t`sex`,\n\t\t\t\t\t\t`visit_1`,\n\t\t\t\t\t\t`visit_2`,\n\t\t\t\t\t\t`visit_3`,\n\t\t\t\t\t\t`visit_4`,\n\t\t\t\t\t\t`visit_5`,\n\t\t\t\t\t\t`visit_6`,\n\t\t\t\t\t\t`visit_7`,\n\t\t\t\t\t\t`visit_8`,\n\t\t\t\t\t\t`visit_9`,\n\t\t\t\t\t\t`coupe`,\n\t\t\t\t\t\t`payment`,\n\t\t\t\t\t\t`total_sum`,\n\t\t\t\t\t\t`org_paid`,\n\t\t\t\t\t\t`org_paid_date`,\n\t\t\t\t\t\t`total_sum`,\n\t\t\t\t\t\t`comments`,\n\t\t\t\t\t\t`org_comments`,\n\t\t\t\t\t\t`mark_del`\n\t\t\t\t\t\tFROM `wt_{$glob_year}`\n\t\t\t\t\t\tORDER BY id") or die("<b>јшыпко:</b> MySQL error: " . mysql_error()); $arr = array(); while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { array_push($arr, $row); } /*foreach($arr as $k=>$v) { if ($k=='phone_m'){ $arr[$k]=chunk_split($v,3,"-");} }*/ mysql_free_result($res); createCSV($arr, "WT" . $glob_year . "People", 1); /* * *This function will return a .csv from a given array inside the $_SESSION['my_array'] * *$sql_res -> the sql query result *$csv_name -> the name we want the csv has to *$download -> true or false to download the csv file after done * */ function createCSV($my_array, $csv_name, $download) { if (count($my_array) < 1) { echo "No data in table!"; return; } $i = 1;
<?php include "functions.php"; createCSV($_POST['content'], $_POST['file'], $_POST['dir']);
return null; } // store output in a internal buffer ob_start(); // create file stream $df = fopen("php://output", 'w'); // write csv headers (firstName, lastName etc) to filestream fputcsv($df, array_keys(reset($array))); // iterate subsequent rows and write data foreach ($array as $row) { fputcsv($df, $row); } fclose($df); // gets the current buffer contents and delete current output buffer. return ob_get_clean(); } function setHeaders($filename) { // force download header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); // disposition / encoding on response body header("Content-Disposition: attachment;filename={$filename}"); header("Content-Transfer-Encoding: binary"); } // get the data from the query parameters $query_parameters = array($_GET); setHeaders("linkedin-csv-export.csv"); echo createCSV($query_parameters); die;
/** * This handles the export functionality just for a store's product catalog. * * @author unknown * @param string $format */ public function export_catalog($format) { $catalog_columns = $this->Store->get_columns_by_store($this->store_id); $column_order = $column_names = array(); for ($i = 0, $n = count($catalog_columns); $i < $n; $i++) { $column_order[] = $catalog_columns[$i]->db_name; $column_names[] = $catalog_columns[$i]->display_name; } $csv_data = array($column_names); // get all non-archived products $products = $this->Product->get_products_for_store($this->store_id); //$products = $this->Product->getByStore($this->store_id); for ($i = 0, $n = count($products); $i < $n; $i++) { $row = array(); foreach ($column_order as $column) { switch ($column) { case 'wholesale_price': $price = getPricePoint($products[$i]['upc_code'], $this->store_id, $column); $price = empty($price) ? '0.00' : number_format($price, 2, '.', ''); $row[] = $price; break; case 'retail_price': $price = getPricePoint($products[$i]['upc_code'], $this->store_id, $column); $price = empty($price) ? '0.00' : number_format($price, 2, '.', ''); $row[] = $price; break; case 'price_floor': $price = getPricePoint($products[$i]['upc_code'], $this->store_id, $column); $price = empty($price) ? '0.00' : number_format($price, 2, '.', ''); $row[] = $price; break; default: $row[] = isset($products[$i][$column]) ? $products[$i][$column] : ''; } } $csv_data[] = $row; } $name = 'catalog'; /* if ($this->store_id !== 'all') $name = str_replace(' ', '_', $this->store_data['store_name']); */ // get current store being viewed $store = $this->Store->get_store_by_id_array($this->store_id); $name = str_replace(' ', '_', $store['store_name']); $name .= '_' . date('Y-m-d'); if ($format == 'excel') { createCSV($csv_data, $name); } else { createPDF($csv_data, $name); } exit; }