thinkphp导入

编写简单的thinkphp导入的功能,大体的逻辑要自己编写。

下面这些代码都是可以直接copy到你的代码里面的。

set_time_limit(0);  //括号里边的数字是执行时间,如果为零说明永久执行直到程序结束,如果为大于零的数字,则不管程序是否执行完成,到了设定的秒数,程序结束。 
ini_set('memory_limit', '500M');  //
/*创建PHPEXCLE读取,默认excel2007,最好兼容csv格式*/
import("ORG/PHPExcel/PHPExcel");
//$filePath = '/home/t/桌面/10-27帐号额度.xls'; 
$filePath =$_FILES['file']['tmp_name'];
$PHPReader = new PHPExcel_Reader_Excel2007();
if (!$filePath) {
echo "<h1 style='color: red'> file don't exist! </h1>";
return;
}
if (!$PHPReader->canRead($filePath)) {
$PHPReader = new PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filePath)) {
$PHPReader = new PHPExcel_Reader_CSV();
if (!$PHPReader->canRead($filePath)) {
echo 'no Excel';
return;
}
}
}
$PHPExcel = $PHPReader->load($filePath);

$currentSheet = $PHPExcel->getSheet(0);

/*取得一共有多少列*/
$allColumn = $currentSheet->getHighestColumn();
/*取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();

原文地址:https://www.cnblogs.com/kobigood/p/4070569.html