I think this is a bug in PHPExcel in ClassesPHPExcelWriterExcel2007.php
. Its easy to fix.
Short answer is: comment out or remove lines 235-237. That would be this code:
if (file_exists($pFilename)) {
unlink($pFilename);
}
Your code will work then. I've checked, it works for me now.
Now, some longer explanation. On lines 235-243 there is this code:
if (file_exists($pFilename)) {
unlink($pFilename);
}
// Try opening the ZIP file
if ($objZip->open($pFilename, $zipOverWrite) !== true) {
if ($objZip->open($pFilename, $zipCreate) !== true) {
throw new PHPExcel_Writer_Exception("Could not open " . $pFilename . " for writing.");
}
}
Now, in this code, three things take place in order:
- If we're saving data to existing file, then this file is deleted (
unlink
)
- If we're saving data to existing file, overwrite this file
- If we're saving data to non-existing file, create it
As you see, operation from step 2 is never executed because in step 1 file is always deleted. And in this process all previously existing file attachments are lost. That's why later you get error File XXX does not exist
- indeed, your earlier image files are not present in newly created file.
Obvious fix to this problem is to remove step 1. If file exists, it should be overwritten. I do not see any logical explanation for step 1. Maybe its a left over from some old code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…