我不得不强制下载excel文件。如我所愿,文件正被完美地下载。但问题是,当我要更改和保存文件的内容时,显示出的错误就好像我无法访问更改文件一样。所以,我必须在下载文件时设置文件的权限。但我不知道怎么做。如果有人能回答的话,我们会很感激的。这是我的代码,它可以很好地作为下载文件。
$filename = 'myfile.xlsx';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data"; //$header and $data are the array contains data with '\t' (tabular form data).因为我改变了我的代码。但问题依然存在。问题是,此代码仅将权限设置为仅在服务器端创建的文件,而不是在客户端下载的文件。这是更新的代码。
$filename = 'myfile.xlsx';
$fp = fopen('/var/www/html/cakephp-3.0/webroot/downloads/' . $filename, 'w');
fwrite($fp, "$header\n$data");
fclose($fp);
chmod('/var/www/html/cakephp-3.0/webroot/downloads/' . $filename, 0777);
// Generate Excel File
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
readfile('/var/www/html/cakephp-3.0/webroot/downloads/' . $filename);https://stackoverflow.com/questions/34715448
复制相似问题