1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263:
<?php
class PHPShopReadCsvNative {
var $delim = ';';
var $size = 10000;
var $title_clean = true;
var $TableName;
function __construct($file) {
global $link_db;
$this->read($file);
$this->link_db = $link_db;
}
function read($file) {
if (file_exists($file)) {
$fp = @fopen($file, "r");
$i = 0;
if ($this->title_clean)
$i = 0;
else
$i = 1;
while (($data = @fgetcsv($fp, $this->size, $this->delim)) !== FALSE) {
if ($i > 0)
$this->CsvToArray[] = $data;
$i++;
}
fclose($fp);
}
else
echo ("" . $file);
}
function CheckUid($uid) {
$sql = "select id from " . $this->TableName . " where uid='$uid'";
$result = mysqli_query($this->link_db, $sql);
return intval(mysqli_num_rows($result));
}
function CheckId($id) {
$sql = "select id from " . $this->TableName . " where id=".intval($id);
$result = mysqli_query($this->link_db, $sql);
return intval(mysqli_num_rows($result));
}
function __call($name, $arguments) {
echo "" . __CLASS__ . '.' . $name;
}
function CsvToArray() {
return $this->CsvToArray;
}
}
class PHPShopReadCsvPro extends PHPShopReadCsv {
var $CsvContent;
var $ReadCsvRow;
var $TableName;
var $CsvToArray;
function __construct() {
$this->ReadCsvRow();
$this->CsvToArray();
}
function ReadCsvRow() {
$csv_lines = $this->CsvContent;
array_shift($csv_lines);
$column = null;
if (is_array($csv_lines)) {
$cnt = count($csv_lines);
for ($i = 0; $i < $cnt; $i++) {
$line = $csv_lines[$i];
$line = trim($line);
$first_char = true;
$col_num = 0;
$length = strlen($line);
for ($b = 0; $b < $length; $b++) {
if (@$skip_char != true) {
$process = true;
if ($first_char == true) {
if ($line[$b] == '"') {
$terminator = '";';
$process = false;
}
else
$terminator = ';';
$first_char = false;
}
if ($line[$b] == '"') {
$next_char = $line[$b + 1];
if ($next_char == '"')
$skip_char = true;
elseif ($next_char == ';') {
if ($terminator == '";') {
$first_char = true;
$process = false;
$skip_char = true;
}
}
}
if ($process == true) {
if ($line[$b] == ';') {
if ($terminator == ';') {
$first_char = true;
$process = false;
}
}
}
if ($process == true)
$column .= $line[$b];
if ($b == ($length - 1)) {
$first_char = true;
}
if ($first_char == true) {
$values[$i][$col_num] = $column;
$column = '';
$col_num++;
}
}
else
$skip_char = false;
}
}
$this->CsvToArray = $values;
}
}
function CsvToArray() {
return $this->CsvToArray;
}
function readFile($file) {
if (is_file($file))
return file($file);
else
echo ("" . $file);
}
function __call($name, $arguments) {
if ($name == __CLASS__) {
self::__construct();
}
}
}
class PHPShopReadCsv {
var $CsvContent;
var $ReadCsvRow;
var $TableName;
var $CsvToArray;
function __construct() {
$this->ReadCsvRow();
$this->CsvToArray();
}
function ReadCsvRow() {
$this->ReadCsvRow = explode("\n", $this->CsvContent);
array_shift($this->ReadCsvRow);
array_pop($this->ReadCsvRow);
}
function CleanStr($str) {
$a = str_replace("\"", "", $str);
$a = str_replace("\\", "", $a);
return str_replace("'", "", $a);
}
function CsvToArray() {
while (list($key, $val) = each($this->ReadCsvRow)) {
$array1 = explode(";", $val);
if (!(@$OutArray[$array1[0]]))
$OutArray[$array1[0]] = $this->CleanStr($array1);
else
$OutArray[] = $this->CleanStr($array1);
}
$this->CsvToArray = $OutArray;
return $OutArray;
}
function CheckUid($uid) {
global $link_db;
$num = 0;
$sql = "select id from " . $this->TableName . " where uid='$uid'";
$result = mysqli_query($link_db, $sql);
$num = mysqli_num_rows($result);
return $num;
}
function CheckId($id) {
global $link_db;
$num = 0;
$sql = "select id from " . $this->TableName . " where id='$id'";
$result = mysqli_query($link_db, $sql);
$num = mysqli_num_rows($result);
return $num;
}
function readFile($file) {
@$fp = fopen($file, "r");
if ($fp) {
$fstat = fstat($fp);
$fread = fread($fp, $fstat['size']);
fclose($fp);
return $fread;
}
else
echo ("" . $file);
}
function __call($name, $arguments) {
if ($name == __CLASS__) {
self::__construct();
}
}
}
?>