码迷,mamicode.com
首页 > Web开发 > 详细

phpexcel导出文件

时间:2015-05-12 15:48:21      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:phpexcel

对于PHPExcel,网上的很多内容都是一概按部就班的内容,而且很多都是相互转载的.这个问题困扰了我这么多天,终于别人的几句话就帮我解决了---权限问题.

想必很多做PHP的人都遇到过权限这个问题.

描述一下问题吧:

首先是这段代码:

<html>
<head>
<title>
this is a test
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8"/>
</head>
<body>
<form method="POST" action="<?php $_SERVER["PHP_SELF"] ?>">
<input type="submit" value="update">
<?php
error_reporting(E_ALL);
set_include_path(get_include_path().PATH_SEPARATOR."../Classes/");

require_once("PHPExcel.php");
require_once("PHPExcel/IOFactory.php");

$filename = "phonelist.xls";
//$phpexcel = PHPExcel_IOFactory::load("phonelist.xls");
//$phpWriter = PHPExcel_IOFactory::createWriter($phpexcel, "Excel5");
//$phpWriter->save("./alai.xls");

$phpexcel = PHPExcel_IOFactory::load($filename);
$sheet = $phpexcel->getActiveSheet();
$row_phone = $sheet->getHighestRow();
echo $row_phone;
$sheet->insertNewRowBefore($row_phone, 1);
$sheet->setCellValueByColumnAndRow(0, $row_phone, "name");
$sheet->setCellValueByColumnAndRow(1, $row_phone, "num");

$phpwriter = PHPExcel_IOFactory::createWriter($phpexcel, "Excel5");
$phpwriter->save("alai.xls");

?>
</form>
</body>
</html>
当我使用php命令执行的时候,可以创建一个alai.xls 但是当我用firefox打开,并没有创建文件.


既然是权限问题,当然修改一下权限就行了.那么这个问题产生的原因是什么呢.

首先需要明确的一点,通过火狐打开的,其访问本地文件使用的身份并不是当前用户,在我的系统中,这个用户叫www-data.这就是创建文件失败的原因.

如果要彻底解决上述问题,建议修改属主, chown -R www-data:www-data dstdir(当前的工作目录)

然后修改其它用户可读写.chmod 777 dstdir

ok, 问题解决.

phpexcel导出文件

标签:phpexcel

原文地址:http://blog.csdn.net/cp3alai/article/details/45665283

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!