我試圖使用crontab運行腳本,但是即使從命令行我也遇到問題。該腳本在瀏覽器中運行良好,並在reports/
文件夾中創建了一些excel文件,該文件夾歸apache
所有。腳本文件歸我所有:john
。從命令行在PHP上拒絕的權限
當我嘗試從命令行運行腳本時,出現以下警告,並且不會創建excel文件。我嘗試了完整的路徑,但我得到了相同的結果。
這是我後,我嘗試從命令行
public_html]$ php include/tests/mailme.php
PHP Warning: fopen(reports/4-March.xls): failed to open stream: Permission denied in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 90
Warning: fopen(reports/4-March.xls): failed to open stream: Permission denied in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 90
PHP Fatal error: Uncaught exception 'Exception' with message 'Can't open reports/4-March.xls. It may be in use or protected.' in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php:93
Stack trace:
#0 /home/john/public_html/PHPExcel/Writer/Excel5.php(233): PHPExcel_Shared_OLE_PPS_Root->save('reports/...')
#1 /home/john/public_html/include/generate_daily_excel.inc(401): PHPExcel_Writer_Excel5->save('reports/...')
#2 /home/john/public_html/include/tests/mailme.php(41): generateDailyExcel('04-02-2013')
#3 {main}
thrown in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 93
Fatal error: Uncaught exception 'Exception' with message 'Can't open reports/4-March.xls. It may be in use or protected.' in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php:93
Stack trace:
#0 /home/john/public_html/PHPExcel/Writer/Excel5.php(233): PHPExcel_Shared_OLE_PPS_Root->save('reports/...')
#1 /home/john/public_html/include/generate_daily_excel.inc(401): PHPExcel_Writer_Excel5->save('reports/...')
#2 /home/john/public_html/include/tests/mailme.php(41): generateDailyExcel('04-02-2013')
#3 {main}
thrown in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 93
我認爲如果我改變的reports
所有者,瀏覽器版本將不會被允許保存運行該腳本。我不熟悉Linux和權利。
我不會特別推薦以root身份運行,避免以root身份運行任何東西,除非您必須 – 2013-03-04 19:40:48
我同意Mark的意見。並編輯我的評論。 – Kovge 2013-03-05 09:19:42