| Server IP : 172.67.187.206 / Your IP : 172.71.28.155 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Inetpub/www/news/elearning/admin/Import_Excel2007/ |
Upload File : |
<!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>
<?php
//รับค่าจาก upload_q.php
$id=$_GET["id"];
?>
<?php
//error_reporting(E_ALL);
error_reporting(E_ALL ^ E_DEPRECATED);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Asia/Bangkok');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"filexlsx/".$_FILES["filUpload"]["name"]))
{
echo "เพิ่มข้อมูลเรียบร้อย<br>";
$urlfile="filexlsx/".$_FILES["filUpload"]["name"];
/** PHPExcel */
require_once 'PHPExcel.php';
/** PHPExcel_IOFactory - Reader */
include 'PHPExcel/IOFactory.php';
$inputFileName = "$urlfile";
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
$headingsArray = $headingsArray[1];
$r = -1;
$namedDataArray = array();
for ($row = 2; $row <= $highestRow; ++$row) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
foreach($headingsArray as $columnKey => $columnHeading) {
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
}
}
}
//echo '<pre>';
//var_dump($namedDataArray);
//echo '</pre><hr />';
//*** Connect to MySQL Database ***//
require '../../configs/host.php';
$i = 0;
foreach ($namedDataArray as $result) {
$i++;
$strSQL = "";
$strSQL .= "INSERT INTO exp_questions_bank ";
$strSQL .= "(qb_subject_id,sort_order,qb_question,qb_option1,qb_option2,qb_option3,qb_option4,qb_answer) ";
$strSQL .= "VALUES ";
$strSQL .= "('$id','".$result["ข้อที่"]."','".$result["คำถาม"]."','".$result["ตัวเลือก1"]."','".$result["ตัวเลือก2"]."','".$result["ตัวเลือก3"]."','".$result["ตัวเลือก4"]."','".$result["คำตอบ"]."') ";
mysql_query($strSQL) or die(mysql_error());
echo "Row $i '".$result["คำถาม"]."'...<br>";
}
mysql_close($cn);
} else {
echo "ไม่สามารถเพิ่มข้อมูลได้";
}
?>
</body>
</html>