首页 > 代码库 > thinkphp导入

thinkphp导入

1.页面:

<div class="container">
<div style=" margin:10px;">
<div class="page-header"><h5>当前位置:导入界面</h5></div>
<form action="__URL__/import" method="post" enctype="multipart/form-data">
<div class="hengdiv">
<label>店铺费用</label>
<input type="button" class="btn btn-success" value="http://www.mamicode.com/下载示例模板"
onclick="window.location.href=http://www.mamicode.com/‘__ROOT__/Public/excelmodel/feemodel.xlsx‘"/>
<input type="file" name="xls" style="height:23px;" class="btn"/>
<input type="submit" class="btn btn-success" value="http://www.mamicode.com/导入"/>
</div>
</form>
<div>
<?php if(isset($errors)){foreach($errors as $error){ ?>
<p style="color: #ff2328;"><?php echo $error; ?></p>
<?php }}elseif(isset($success)){ ?>
<p style="color: #53ff49;"><?php echo $success; ?></p>
<?php } ?>
</div>
</div>
</div>


2.控制器:
public function import()
{
set_time_limit(0);
ini_set("memory_limit","500M");
if(isset($_FILES[‘xls‘])){
import("ORG/PHPExcel/PHPExcel");
$xls = $_FILES [‘xls‘] [‘tmp_name‘];
$name = $_FILES [‘xls‘] [‘name‘];

$name = explode(‘.‘,$name); //字符串转化为数组。

if($xls AND ($name[1]==‘xls‘ OR $name[1]==‘xlsx‘)){
$objPHPExcel = PHPExcel_IOFactory::load($xls);
$data = http://www.mamicode.com/$objPHPExcel->getSheet(0)
->toArray(NULL,TRUE,TRUE,TRUE);
print_r($data);exit;//这里就是取值。。
}
}


$this->display();
}

thinkphp导入