我有以下代码应该保存在文件服务器中:
$month_name = "MARCH2014";
$objWriter->save(str_replace(__FILE__,"C:\xampp\htdocs\timesheet\files\{$month_name}\{$username}.xlsx",__FILE__));
我一直收到以下错误:
Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Could not close zip file C: mpp\htdocs imesheetiles\{MARCH2014}\{HS0103}.xlsx.' in C:\xampp\htdocs\timesheet\application\third_party\PHPExcel\Writer\Excel2007.php:399 Stack trace: #0 C:\xampp\htdocs\timesheet\application\controllers\time_sheet.php(6132): PHPExcel_Writer_Excel2007->save('C:?mpp\htdocs?i...') #1 [internal function]: Time_sheet->save_time_sheet() #2 C:\xampp\htdocs\timesheet\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #3 C:\xampp\htdocs\timesheet\index.php(202): require_once('C:\xampp\htdocs...') #4 {main} thrown in C:\xampp\htdocs\timesheet\application\third_party\PHPExcel\Writer\Excel2007.php on line 399
但是当我使用以下内容时:
$objWriter->save(str_replace(__FILE__,"C:\xampp\htdocs\timesheet\files\MARCH2014\HS0103.xlsx",__FILE__));
我没有错, 请告诉我我做错了什么?
答案 0 :(得分:0)
标准PHP转义字符:
"C:\xampp\htdocs\timesheet\files\{$month_name}\{$username}.xlsx"
试图逃跑
\xa => character <hex 0a> (<Line feed>)
\h => ???
\t => <tab character>
\f => ???
如果您希望\
为\
而不是PHP中转义序列的第一个字符,则需要将其转义为\\
所以
"C:\\xampp\\htdocs\\timesheet\\files\\{$month_name}\\{$username}.xlsx"
另一种方法是使您的目录路径安全&#34;通过使用unix目录分隔符(/
),它仍可以在Windows和Mac上运行
"/xampp/htdocs/timesheet/files/{$month_name}/{$username}.xlsx"