Read-only excel file

Topics: Project Management Forum, User Forum
Jul 27, 2009 at 4:17 PM

For the assistance of forum's member. I have solved the download excel issue. However, now I am having another issue of opens and saves the excel file.
I found that after open the file and I enter some value to the file and try to save it. It will say that the file is read-only and I need to re-save again instead. Is it anyway to create a non-read-only file?

Jul 27, 2009 at 7:16 PM

I have never heard of this issue. Can you describe what steps are involved to reproduce this? Please provide some sample code, platform, browser information, screenshots if possible.

Dec 22, 2009 at 6:57 PM
Edited Dec 23, 2009 at 5:56 PM

I had this same issue of read only files that were output to disk (but not with those files pushed for download.) Apache 2.2.14, php 5.3, Mac OS X. For me, it was an issue of file permissions - the saved file's owner was Apache (_www) and writeable for Apache only:

$ ls -l *.xlsx
-rw-r--r-- 1 _www wheel 6339 Dec 18 14:11 test.xlsx

To solve this, I modified the function save() in PHPExcelLib/Classes/PHPExcel/Writer/Excel2007.php @ line 403

// If a temporary file was used, copy it to the correct file stream
if ($originalFilename != $pFilename) {
if (copy($pFilename, $originalFilename) === false) {
throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");

// change file permissions for a SAVED file... a DOWNLOADED file doesn't need this
//echo 'Changing permissions from ', substr(sprintf('%o', fileperms($originalFilename)), -4), "\n";
if (file_exists($originalFilename) and chmod($originalFilename, 0664) === false) {
throw new Exception("Could not change file permissions for $originalFilename.");

Resulting permissions (I'm a member of group wheel, so I can write to the file):

$ ls -l *.xlsx
-rw-rw-r-- 1 _www wheel 6339 Dec 18 15:20 test.xlsx

HTH, Thom