u011626087 于 2014.08.21 11:04 提问
- 用PHP实现excel数据导入数据库,但是提示500错误,服务器是IIS,求高手指点
-
require_once ('PHPExcel.php'); require_once ('PHPExcel/IOFactory.php'); require_once ('PHPExcel/Reader/Excel5.php'); if($_POST['leadExcel'] == "true") { $filename = $_FILES['inputExcel']['name']; $tmp_name = $_FILES['inputExcel']['tmp_name']; //自己设置的上传文件存放路径 $filePath = '../../upfile/'; $str = ""; //注意设置时区 $time=date("y-m-d-H-i-s");//去当前上传的时间 //获取上传文件的扩展名 $extend=strrchr($filename,'.'); //上传后的文件名 $name=$time.$extend; $uploadfile=$filePath.$name;//上传后的文件名地址 //move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。 $result=move_uploaded_file($tmp_name,$uploadfile);//假如上传到当前目录下 if($result) //如果上传文件成功,就执行导入excel操作 { $objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format $objPHPExcel = $objReader->load($uploadfile); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数 $headtitle=array(); for ($row = 2;$row <= $highestRow;$row++) { $strs=array(); //注意highestColumnIndex的列数索引从0开始 for ($col = 0;$col < $highestColumnIndex;$col++) { if($col==3){ $strs[$col] =excelTime($objWorksheet->getCellByColumnAndRow($col, $row)->getValue()); }else{ $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); } } $sql = "INSERT INTO phonecard(batch, cardpwd, fee, outdate, cardno,status) VALUES ( '{$strs[0]}', '{$strs[1]}', {$strs[2]}, '{$strs[3]}', '{$strs[4]}', {$strs[5]})"; $res=$user->InsertCard($sql); if(!$res) { return false; echo 'sql语句有误'; }else{ $str = ""; } } unlink($uploadfile); //删除上传的excel文件 } echo "<script>alert('导入成功!');window.location.href='huiyuanlist.php'</script>"; }
-
- smnna 2014.11.25 23:48
问题解决了吗,我也遇到同样问题,求指点,感激不尽!!!!,,,,,,405700753@qq.com
-
- smnna 2014.11.25 23:49
问题解决了吗,我也遇到同样问题,求指点,感激不尽!!!!,,,,,,405700753@qq.com
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
- 其他相关推荐