<?php
include_once("inc/auth.inc.php");//include_once("PHPExcel/PHPExcel.php");
//include_once("PHPExcel/PHPExcel/IOFactory.php");
//include_once("PHPExcel/PHPExcel/Reader/Excel5.php");
header("Content-Type:text/html;charset=utf-8");
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
/****** Include the EXCEL Reader Factory ***********///header("Content-Type:text/html;charset=utf-8");
/****** Include the EXCEL Reader Factory ***********/
error_reporting(0);
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';
echo $_FILES['excelupload']['name'];if(isset($_POST) && !empty($_FILES['excelupload']['name']))
{
//print_r($_FILES['excelupload']);
$namearr = explode(".",$_FILES['excelupload']['name']);
if(end($namearr) != 'xls' && end($namearr) != 'xlsx')
{
echo '<p> Invalid File </p>';
$invalid = 1;
}
if($invalid != 1)
{
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["excelupload"]["name"]);
// echo $target_file;
// $target_file = iconv('latin1', 'GBK', $target_file);
$response = move_uploaded_file($_FILES['excelupload']['tmp_name'],$target_file);
if($response)
{
try {
$objPHPExcel = PHPExcel_IOFactory::load($target_file);
} catch(Exception $e) {
die('Error : Unable to load the file : "'.pathinfo($_FILES['excelupload']['name'],PATHINFO_BASENAME).'": '.$e->getMessage());
}
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
// $objWriter->setUseBOM(true);
//print_r($allDataInSheet);
$arrayCount = count($allDataInSheet); // Total Number of rows in the uploaded EXCEL file
//echo $arrayCount;
// $string = "INSERT INTO `test2` (`Sr.No.`,`Emp ID`, `Name`, `Address`) VALUES ";
for($i=2;$i<=$arrayCount;$i++){
$create_dept= trim($allDataInSheet[$i]["B"]);
$manager = trim($allDataInSheet[$i]["C"]);
$name = trim($allDataInSheet[$i]["D"]);
$num = trim($allDataInSheet[$i]["E"]);
$status = trim($allDataInSheet[$i]["F"]);
$start_time = trim($allDataInSheet[$i]["G"]);
$est_end_time = trim($allDataInSheet[$i]["H"]);
$type = trim($allDataInSheet[$i]["I"]);
$budget = trim($allDataInSheet[$i]["J"]);
$pay = trim($allDataInSheet[$i]["K"]);
$cost = trim($allDataInSheet[$i]["L"]);
$desc = trim($allDataInSheet[$i]["M"]);
$dept = trim($allDataInSheet[$i]["N"]);
$l2type = trim($allDataInSheet[$i]["O"]);
echo $create_dept;
echo $name;
// $conn = mysql_connect("localhost","root","");
// mysql_select_db("test",$conn);
// mysql_query("set names 'UTF-8'");
$string = "INSERT INTO testdb (
PROJ_ID,
PROJ_CREATE_DEPT,
PROJ_MANAGER,
PROJ_NAME,
PROJ_NUM,
PROJ_STATUS,
PROJ_START_TIME,
PROJ_EST_END_TIME,
PROJ_CREATE_TYPE,
PROJ_BUDGET,
PROJ_SIGNED_COST,
PROJ_REAL_COST,
PROJ_DESCRIPTION,
PROJ_DEPT,
PROJ_L2_TYPE,
PROJ_UPDATE_TIME
) VALUES (
'',
'$create_dept',
'$manager',
'$name',
'$num',
'$status',
'$start_time',
'$est_end_time',
'$type',
'$budget',
'$pay',
'$cost',
'$desc',
'$dept',
'$l2type',
now()
)";
exequery(TD::conn(),$string);
}
}
}// End Invalid Condition
echo "<div style='color:#3C7C64'>Import Succesful</div>";
}
?>show variables like "%char%";
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | E:\MYOA\mysql5\share\charsets\ |
+--------------------------+--------------------------------+我在页面上直接打印变量echo $create_dept;
echo $name;能正常输入中文,但mysql中是乱码,而且其他页面输入中文的问题不存在乱码的情况。请高手指点下。
include_once("inc/auth.inc.php");//include_once("PHPExcel/PHPExcel.php");
//include_once("PHPExcel/PHPExcel/IOFactory.php");
//include_once("PHPExcel/PHPExcel/Reader/Excel5.php");
header("Content-Type:text/html;charset=utf-8");
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
/****** Include the EXCEL Reader Factory ***********///header("Content-Type:text/html;charset=utf-8");
/****** Include the EXCEL Reader Factory ***********/
error_reporting(0);
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';
echo $_FILES['excelupload']['name'];if(isset($_POST) && !empty($_FILES['excelupload']['name']))
{
//print_r($_FILES['excelupload']);
$namearr = explode(".",$_FILES['excelupload']['name']);
if(end($namearr) != 'xls' && end($namearr) != 'xlsx')
{
echo '<p> Invalid File </p>';
$invalid = 1;
}
if($invalid != 1)
{
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["excelupload"]["name"]);
// echo $target_file;
// $target_file = iconv('latin1', 'GBK', $target_file);
$response = move_uploaded_file($_FILES['excelupload']['tmp_name'],$target_file);
if($response)
{
try {
$objPHPExcel = PHPExcel_IOFactory::load($target_file);
} catch(Exception $e) {
die('Error : Unable to load the file : "'.pathinfo($_FILES['excelupload']['name'],PATHINFO_BASENAME).'": '.$e->getMessage());
}
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
// $objWriter->setUseBOM(true);
//print_r($allDataInSheet);
$arrayCount = count($allDataInSheet); // Total Number of rows in the uploaded EXCEL file
//echo $arrayCount;
// $string = "INSERT INTO `test2` (`Sr.No.`,`Emp ID`, `Name`, `Address`) VALUES ";
for($i=2;$i<=$arrayCount;$i++){
$create_dept= trim($allDataInSheet[$i]["B"]);
$manager = trim($allDataInSheet[$i]["C"]);
$name = trim($allDataInSheet[$i]["D"]);
$num = trim($allDataInSheet[$i]["E"]);
$status = trim($allDataInSheet[$i]["F"]);
$start_time = trim($allDataInSheet[$i]["G"]);
$est_end_time = trim($allDataInSheet[$i]["H"]);
$type = trim($allDataInSheet[$i]["I"]);
$budget = trim($allDataInSheet[$i]["J"]);
$pay = trim($allDataInSheet[$i]["K"]);
$cost = trim($allDataInSheet[$i]["L"]);
$desc = trim($allDataInSheet[$i]["M"]);
$dept = trim($allDataInSheet[$i]["N"]);
$l2type = trim($allDataInSheet[$i]["O"]);
echo $create_dept;
echo $name;
// $conn = mysql_connect("localhost","root","");
// mysql_select_db("test",$conn);
// mysql_query("set names 'UTF-8'");
$string = "INSERT INTO testdb (
PROJ_ID,
PROJ_CREATE_DEPT,
PROJ_MANAGER,
PROJ_NAME,
PROJ_NUM,
PROJ_STATUS,
PROJ_START_TIME,
PROJ_EST_END_TIME,
PROJ_CREATE_TYPE,
PROJ_BUDGET,
PROJ_SIGNED_COST,
PROJ_REAL_COST,
PROJ_DESCRIPTION,
PROJ_DEPT,
PROJ_L2_TYPE,
PROJ_UPDATE_TIME
) VALUES (
'',
'$create_dept',
'$manager',
'$name',
'$num',
'$status',
'$start_time',
'$est_end_time',
'$type',
'$budget',
'$pay',
'$cost',
'$desc',
'$dept',
'$l2type',
now()
)";
exequery(TD::conn(),$string);
}
}
}// End Invalid Condition
echo "<div style='color:#3C7C64'>Import Succesful</div>";
}
?>show variables like "%char%";
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | E:\MYOA\mysql5\share\charsets\ |
+--------------------------+--------------------------------+我在页面上直接打印变量echo $create_dept;
echo $name;能正常输入中文,但mysql中是乱码,而且其他页面输入中文的问题不存在乱码的情况。请高手指点下。
解决方案 »
- 求教关于在window xp下自己搭建的PHP环境mail发送邮件的问题!
- php的角色权限控制数据库表设如何设计?
- 刚写的SQL,语法上 有问题吗?求助大家。
- 如何使用CURL扩展来发送和接收XML格式的数据
- 关于jqgrid的问题
- PHP 无限循环获取数据(或消息)信息
- Use of undefined constant nowsdate - assumed 怎么回事
- session的一个问题
- 怎么取得两时间之间间隔的秒数,如2003-06-30 1
- 大家好,csdn,php版的朋友们,如果大家晚上有问题的话,不妨到我们所在的论坛www.hycenter.net提问,一个纯文本论坛,非宣传;
- 小女子这厢有礼啦
- 做一个酒吧座位预定系统,求思路。
必须要有!
我之前加了,加在exequery(TD::conn(),$string); 之前,试了也不行啊
如果是调用你的数据库操作类,那么你的在他里面设置字符集
$conn = mysql_connect("localhost","root","myoa888");
mysql_select_db("TD_OA",$conn);
mysql_query("set names 'UTF-8'");
mysql_query($string);加了这一段,貌似写不进去呢,他会覆盖前面的数据库连接吗
是 mysql_query("set names utf8");