<?php
global $wpdb;
// Table name
$tablename = $wpdb->prefix."customplugin";
// Import CSV
if(isset($_POST['butimport'])){
// File extension
$extension = pathinfo($_FILES['import_file']['name'], PATHINFO_EXTENSION);
// If file extension is 'csv'
if(!empty($_FILES['import_file']['name']) && $extension == 'csv'){
$totalInserted = 0;
// Open file in read mode
$csvFile = fopen($_FILES['import_file']['tmp_name'], 'r');
fgetcsv($csvFile); // Skipping header row
// Read file
while(($csvData = fgetcsv($csvFile)) !== FALSE){
$csvData = array_map("utf8_encode", $csvData);
// Row column length
$dataLen = count($csvData);
// Skip row if length != 4
if( !($dataLen == 8) ) continue;
// Assign value to variables
$tarih = trim($csvData[0]);
$lgk = trim($csvData[1]);
$etakim = trim($csvData[2]);
$dtakim = trim($csvData[3]);
$gilkyari = trim($csvData[4]);
$gmacsonucu = trim($csvData[5]);
$tilkyari = trim($csvData[6]);
$tmacsonucu = trim($csvData[7]);
// Check record already exists or not
$cntSQL = "SELECT count(*) as count FROM {$tablename} where etakim='".$etakim."'";
$record = $wpdb->get_results($cntSQL, OBJECT);
if($record[0]->count==0){
// Check if variable is empty or not
if(!empty($tarih) && !empty($lgk) && !empty($etakim) && !empty($dtakim) ) {
// Insert Record
$wpdb->insert($tablename, array(
'tarih' =>$tarih,
'lgk' =>$lgk,
'etakim' =>$etakim,
'dtakim' =>$dtakim,
'gilkyari' =>$gilkyari,
'gmacsonucu' =>$gmacsonucu,
'tilkyari' =>$tilkyari,
'tmacsonucu' => $tmacsonucu
));
if($wpdb->insert_id > 0){
$totalInserted++;
}
}
}
}
echo "<h3 style='color: green;'>Total record Inserted : ".$totalInserted."</h3>";
}else{
echo "<h3 style='color: red;'>Invalid Extension</h3>";
}
}
?>
<h2>All Entries</h2>
<!-- Form -->
<form method='post' action='<?= $_SERVER['REQUEST_URI']; ?>' enctype='multipart/form-data'>
<input type="file" name="import_file" >
<input type="submit" name="butimport" value="Import">
</form>
<!-- Record List -->
<table width='100%' border='1' style='border-collapse: collapse;'>
<thead>
<tr>
<th>S.no</th>
<th>Date</th>
<th>League</th>
<th>Home Team</th>
<th>Away Team</th>
<th>Half Time</th>
<th>Full Time</th>
<th>Half Time</th>
<th>Full Time</th>
</tr>
</thead>
<tbody>
<?php
// Fetch records
$entriesList = $wpdb->get_results("SELECT * FROM ".$tablename." order by id desc");
if(count($entriesList) > 0){
$count = 0;
foreach($entriesList as $entry){
$id = $entry->id;
$tarih = $entry->tarih;
$lgk = $entry->lgk;
$etakim = $entry->etakim;
$dtakim = $entry->dtakim;
$gilkyari = $entry->gilkyari;
$gmacsonucu = $entry->gmacsonucu;
$tilkyari = $entry->tilkyari;
$tmacsonucu = $entry->tmacsonucu;
echo "<tr>
<td>".++$count."</td>
<td>".$tarih."</td>
<td>".$lgk."</td>
<td>".$etakim."</td>
<td>".$dtakim."</td>
<td>".$gilkyari."</td>
<td>".$gmacsonucu."</td>
<td>".$tilkyari."</td>
<td>".$tmacsonucu."</td>
</tr>
";
}
}else{
echo "<tr><td colspan='5'>No record found</td></tr>";
}
?>
</tbody>
</table>
böyle bir kod satırım var kendi pluginimi geliştirmeye çalışıyorum acemiyim csv dosyam yükleniyor herşey tamam ama türkçe karakter sorunlu yükleniyor acaba nerde yanlış yapıyorum hocalarım.Yardımcı olursanız sevinirim
global $wpdb;
// Table name
$tablename = $wpdb->prefix."customplugin";
// Import CSV
if(isset($_POST['butimport'])){
// File extension
$extension = pathinfo($_FILES['import_file']['name'], PATHINFO_EXTENSION);
// If file extension is 'csv'
if(!empty($_FILES['import_file']['name']) && $extension == 'csv'){
$totalInserted = 0;
// Open file in read mode
$csvFile = fopen($_FILES['import_file']['tmp_name'], 'r');
fgetcsv($csvFile); // Skipping header row
// Read file
while(($csvData = fgetcsv($csvFile)) !== FALSE){
$csvData = array_map("utf8_encode", $csvData);
// Row column length
$dataLen = count($csvData);
// Skip row if length != 4
if( !($dataLen == 8) ) continue;
// Assign value to variables
$tarih = trim($csvData[0]);
$lgk = trim($csvData[1]);
$etakim = trim($csvData[2]);
$dtakim = trim($csvData[3]);
$gilkyari = trim($csvData[4]);
$gmacsonucu = trim($csvData[5]);
$tilkyari = trim($csvData[6]);
$tmacsonucu = trim($csvData[7]);
// Check record already exists or not
$cntSQL = "SELECT count(*) as count FROM {$tablename} where etakim='".$etakim."'";
$record = $wpdb->get_results($cntSQL, OBJECT);
if($record[0]->count==0){
// Check if variable is empty or not
if(!empty($tarih) && !empty($lgk) && !empty($etakim) && !empty($dtakim) ) {
// Insert Record
$wpdb->insert($tablename, array(
'tarih' =>$tarih,
'lgk' =>$lgk,
'etakim' =>$etakim,
'dtakim' =>$dtakim,
'gilkyari' =>$gilkyari,
'gmacsonucu' =>$gmacsonucu,
'tilkyari' =>$tilkyari,
'tmacsonucu' => $tmacsonucu
));
if($wpdb->insert_id > 0){
$totalInserted++;
}
}
}
}
echo "<h3 style='color: green;'>Total record Inserted : ".$totalInserted."</h3>";
}else{
echo "<h3 style='color: red;'>Invalid Extension</h3>";
}
}
?>
<h2>All Entries</h2>
<!-- Form -->
<form method='post' action='<?= $_SERVER['REQUEST_URI']; ?>' enctype='multipart/form-data'>
<input type="file" name="import_file" >
<input type="submit" name="butimport" value="Import">
</form>
<!-- Record List -->
<table width='100%' border='1' style='border-collapse: collapse;'>
<thead>
<tr>
<th>S.no</th>
<th>Date</th>
<th>League</th>
<th>Home Team</th>
<th>Away Team</th>
<th>Half Time</th>
<th>Full Time</th>
<th>Half Time</th>
<th>Full Time</th>
</tr>
</thead>
<tbody>
<?php
// Fetch records
$entriesList = $wpdb->get_results("SELECT * FROM ".$tablename." order by id desc");
if(count($entriesList) > 0){
$count = 0;
foreach($entriesList as $entry){
$id = $entry->id;
$tarih = $entry->tarih;
$lgk = $entry->lgk;
$etakim = $entry->etakim;
$dtakim = $entry->dtakim;
$gilkyari = $entry->gilkyari;
$gmacsonucu = $entry->gmacsonucu;
$tilkyari = $entry->tilkyari;
$tmacsonucu = $entry->tmacsonucu;
echo "<tr>
<td>".++$count."</td>
<td>".$tarih."</td>
<td>".$lgk."</td>
<td>".$etakim."</td>
<td>".$dtakim."</td>
<td>".$gilkyari."</td>
<td>".$gmacsonucu."</td>
<td>".$tilkyari."</td>
<td>".$tmacsonucu."</td>
</tr>
";
}
}else{
echo "<tr><td colspan='5'>No record found</td></tr>";
}
?>
</tbody>
</table>
böyle bir kod satırım var kendi pluginimi geliştirmeye çalışıyorum acemiyim csv dosyam yükleniyor herşey tamam ama türkçe karakter sorunlu yükleniyor acaba nerde yanlış yapıyorum hocalarım.Yardımcı olursanız sevinirim