|
|
|
ช่วยดู code import excel ให้หน่อยครับ คือมันไม่ลงฐานข้อมูล |
|
|
|
|
|
|
|
Code (PHP)
<?php
@session_start();
/**
* @author chittakune
* @copyright 2012
*/
if($_SESSION['user'] == 'admin')
{
include("header01.php");
}
else
{
include("header02.php");
}
$part1 = array(0,5,6,8,9,10,15,16,18);
$part2 = array(0,20,21,22,23);
$part3 = array(0,25,28,29,30,31);
$part4 = array(0,33,34,35,36,38,39,40);
$part5 = array(0,42,44,45,46,47);
$part6 = array(0,49);
$status = '';
//ini_set('memory_limit', '16');
$garfield=$_POST['garfield'];
echo $_FILES["file"]["type"];
if(isset($_POST['$garfield'])){
//echo "Type: " . $_FILES["file"]["type"] . "<br>";
if ($_FILES["file"]["type"] == "application/vnd.ms-excel")
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
$status = "Upload: " . $_FILES["file"]["name"] . "<br>";
// echo "Type: " . $_FILES["file"]["type"] . "<br>";
$status .= "Size: " . ($_FILES["file"]["size"] / 1024) . " KB<br><br>";
// echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
// echo "Memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB<br>";
require_once '../exceltest/reader.php';
// ExcelFile($filename, $encoding);
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$data->setOutputEncoding('tis620');
$data->read($_FILES["file"]["tmp_name"]);
error_reporting(E_ALL ^ E_NOTICE);
echo '</br>';
include("../mysqlconnect.php");
//ตรวจสอบว่าเป็นไฟล์ข้อมูลของโครงการ 1-5-12 หรือไม่
//
$dup = 0;
$upl = 0;
//วน loop อ่านข้อมูลทั้งหมด
for($i=3; $data->sheets[1]['cells'][$i][1] != '' ; $i++)
{
$stringSQL = "Insert into kubota_1747 ";
$stringSQL .= "(id, id_no, id_center, no_center, name_center, no_reference, no_store, name_store, customer_name, tel, age_car ,date_sent, time_sent, between_time, sex, data_detail,type, int_date, count, result, person, person_submit, week) ";
$stringSQL .= "values ";
$stringSQL .= "('" . $data->sheets[1]['cells'][$i][1] . "', '" . $data->sheets[1]['cells'][$i][2] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][3] . "', '" . $data->sheets[1]['cells'][$i][4] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][5] . "', '" . $data->sheets[1]['cells'][$i][6] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][7] . "', '" . $data->sheets[1]['cells'][$i][8] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][9] . "', '" . $data->sheets[1]['cells'][$i][10] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][11] . "', '" . $data->sheets[1]['cells'][$i][12] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][13] . "', '" . $data->sheets[1]['cells'][$i][14] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][15] . "', '" . $data->sheets[1]['cells'][$i][16] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][17] . "', '" . $data->sheets[1]['cells'][$i][18] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][19] . "', '" . $data->sheets[1]['cells'][$i][20] . "'";
$stringSQL .= ",'" . $data->sheets[1]['cells'][$i][21] . "', '" . $data->sheets[1]['cells'][$i][22] . "')";
$result = mysql_query($stringSQL, $conn) or die(mysql_error());
$status .= '<font color=\'green\'>Uploaded.</font> -- > ' . $data->sheets[1]['cells'][$i][1] . ' - ' . $data->sheets[1]['cells'][$i][22] . '<br>';
$upl++;
}
mysql_close;
$status .= '<br>' . '<font color=\'green\'>Upload Process: Finish.</font>' . '<br>';
$status .= 'Uploaded: '. $upl . '<br>';
$status .= 'Duplicated: '. $dup . '<br>';
}
}
else
{
$status = "<font color='red'>Status: Invalid file</font>";
}
}
?>
<form action="upload1747.php" method="post" enctype="multipart/form-data">
<table border="0" cellpadding="0" cellspacing="0" width="1000">
<tr>
<td background="../images/body-head.jpg" height="30"> </td>
</tr>
<tr>
<td background="../images/body-body.jpg" height="300" align="center">
<table border="1" cellpadding="0" cellspacing="0" width="900" bordercolor="#C0C0C0" style="border-width: 0px">
<tr>
<td width="224" align="center" style="border-style: none; border-width: medium">
<a href="../upload1512.php" style="text-decoration: none"><img border="0" src="../images/content32.png" width="32" height="32"></a></td>
<td width="224" align="center" style="border-style: none; border-width: medium">
<a href="../uploadkaj.php" style="text-decoration: none"><img border="0" src="../images/content32.png" width="32" height="32"></a></td>
<td width="225" align="center" style="border-style: none; border-width: medium">
<a href="importdata1747.php"><img border="0" src="../images/content32.png" width="32" height="32"></a></td>
<td width="225" align="center" style="border-style: none; border-width: medium">
<img border="0" src="../images/content32.png" width="32" height="32"></td>
</tr>
<tr>
<td width="224" align="center" style="border-style: none; border-width: medium">
<b><font size="2">โครงการ 1-5-12</font></b></td>
<td width="224" align="center" style="border-style: none; border-width: medium">
<b><font size="2">โครงการคุ้มอุ่นใจ</font></b></td>
<td width="225" align="center" style="border-style: none; border-width: medium">
<b><font size="2">โครงการ 1747</font></b></td>
<td width="225" align="center" style="border-style: none; border-width: medium"> </td>
</tr>
</table>
<p> </p>
<p> </p>
<p><b><font size="5">Upload File : รายชื่อโครงการ 1747</font></b></p>
<table border="0" cellpadding="0" cellspacing="0" width="510">
<tr>
<td height="30" align="right"> </td>
</tr>
<tr>
<td height="30" align="right">
<p align="center">File : <input type="file" name="file" size="60"></td>
</tr>
<tr>
<td height="30" align="right"><input type="submit" value=" Submit " name="B1" style="float: right"><input type="hidden" name="garfield" value="garfield"></td>
</tr>
<tr>
<td height="30" align="left"> </td>
</tr>
<tr>
<td height="30" align="left"><font size="2"><?echo $status;?></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td background="../images/body-foot.jpg" height="30"> </td>
</tr>
</table>
</form>
<?
include("footer01.php");
?>
Tag : PHP, Excel (Excel.Application)
|
|
|
|
|
|
Date :
2012-06-12 15:47:18 |
By :
b51310134 |
View :
1029 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($_FILES["file"]["type"] == "application/vnd.ms-excel") ตรงนี้ echo ค่าออกมาดูจะเป็น application/octet-stream
|
|
|
|
|
Date :
2012-06-12 15:51:30 |
By :
b51310134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.ระบบอ่านข้อมูลจากไฟล์ได้หรือเปล่า
2.คำสั่งคิวรี่ถูกต้องหรือไม่ echo ออกมาดู ลองเอาไปรันที่ phpmyadminดู
|
|
|
|
|
Date :
2012-06-12 17:12:03 |
By :
naskw |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|