|
|
|
ช่วยดู error domdocumentload php ใน iis ให้หน่อยสิค่ะแก้มาหลายวันแล้วงง!!! |
|
|
|
|
|
|
|
พอดีที่ฝึกงาน ให้เขียนโปรแกรมที่อัพโหลดไฟล์ excel ขึ้นไปแล้วเก็บใน dbmysql เป็นฟิลด์เหมือนใน excel อ่ะค่ะ พอดีเจอตัวอย่างโค๊ดในเว็บๆนึงมาลองทำตามแต่ error แก้หลายวันแล้วงงมากมายคะ
โค๊ด หน้า upload
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form enctype="multipart/form-data" action="import.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<input name="file" type="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>
โค๊ด หน้า import เข้าฐานข้อมูลค่ะ
Code (PHP)
<?php
if ( $_FILES['fileupload']['error'] ) {
die("upload error ");
}
//======Connect DB======================//
$m_host = "localhost";
$m_user = "root";
$m_pass = "root";
$m_name = "vendors";
mysql_connect($m_host,$m_user,$m_pass);
mysql_select_db($m_name);
mysql_query("SET NAMES UTF8");
//======End Connect DB======================//
//======Get data from Excel======================//
$dom = DOMDocument::load( $_FILES['fileupload']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
$row = 0;
foreach ($rows as $temp) {
$col = 0;
if($row==0) {
$row++; continue;
}
$cells = $temp->getElementsByTagName('Cell');
foreach( $cells as $cell ) {
if($col==0) $data1 = $cell->nodeValue;
if($col==1) $data2 = $cell->nodeValue;
if($col==2) $data3 = $cell->nodeValue;
if($col==3) $data4 = $cell->nodeValue;
if($col==4) $data5 = $cell->nodeValue;
if($col==5) $data6 = $cell->nodeValue;
if($col==6) $data7 = $cell->nodeValue;
if($col==7) $data8 = $cell->nodeValue;
if($col==8) $data9 = $cell->nodeValue;
if($col==9) $data10 = $cell->nodeValue;
if($col==10) $data11 = $cell->nodeValue;
if($col==11) $data12 = $cell->nodeValue;
$col++;
}
//======End Get data from Excel======================//
//==================Insert To DB ====================================//
$sql = " INSERT INTO vendor (";
$sql .= " id, ";
$sql .= " location, ";
$sql .= " payvoucher, ";
$sql .= " vendorcode, ";
$sql .= " vendorname";
$sql .= " password, ";
$sql .= " chequeno, ";
$sql .= " pmtdate, ";
$sql .= " thansferamout, ";
$sql .= " witholdingtax ";
$sql .= " accnumber, ";
$sql .= " bankname ";
$sql .= " ) VALUES ( ";
$sql .= " '$data1', ";
$sql .= " '$data2', ";
$sql .= " '$data3', ";
$sql .= " '$data4', ";
$sql .= " '$data5' ";
$sql .= " '$data6', ";
$sql .= " '$data7', ";
$sql .= " '$data8', ";
$sql .= " '$data9', ";
$sql .= " '$data10' ";
$sql .= " '$data11', ";
$sql .= " '$data12' ";
$sql .= " ) ";
mysql_query($sql) or die(mysql_error());
//==================End Insert To DB ====================================//
$row++;
}
mysql_close();
?>
ผลรัน
Warning: DOMDocument::load() [function.DOMDocument-load]: Empty string supplied as input in D:\Intranet2\vendor\import.php on line 18
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\Intranet2\vendor\import.php on line 19
ใช้ iis เป็น websever อ่ะค่ะที่โรงงานเค้าให้ใช้ตัวนี้
Tag : PHP, MySQL, jQuery, Excel (Excel.Application), Class Library, Windows
|
|
|
|
|
|
Date :
2012-07-09 15:18:50 |
By :
ploy |
View :
835 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เค้าให้อัพโหลดไปเก็บในฐานข้อมูลธรรมดาๆ หรือไล่ก๊อปปี้ทีละ cell เข้า field ของ table ใน mysql เลยหรอครับ
|
|
|
|
|
Date :
2012-07-09 18:09:47 |
By :
mangkunzo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|