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, 問題解決.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章