diff --git a/src/Encrypt.php b/src/Encrypt.php index 4c10a63..84203af 100644 --- a/src/Encrypt.php +++ b/src/Encrypt.php @@ -99,10 +99,16 @@ public function output(?string $filePath = null) $encryptionInfoBuffer = EncryptionInfoBuilder::build($encryptionInfo); $OLE = new OLE_PPS_File(OLE::Asc2Ucs('EncryptionInfo')); + if ($this->tmpPathFolder) { + $OLE->setTempDir($this->tmpPathFolder); + } $OLE->init(); $OLE->append(pack('C*', ...$encryptionInfoBuffer)); $OLE2 = new OLE_PPS_File(OLE::Asc2Ucs('EncryptedPackage')); + if ($this->tmpPathFolder) { + $OLE2->setTempDir($this->tmpPathFolder); + } $OLE2->init(); $filesize = filesize($encryptedPackage['tmpFile']); for ($i = 0; $i < ($filesize / 4096); $i++) { diff --git a/tests/EncryptorTest.php b/tests/EncryptorTest.php index f4e9525..ff77e37 100644 --- a/tests/EncryptorTest.php +++ b/tests/EncryptorTest.php @@ -32,7 +32,7 @@ public function test_encryptor_with_binary_data() public function test_encryptor_with_set_temp_path_folder() { - (new Encrypt)->input('Book1.xlsx')->setTempPathFolder('/tmp')->password('111')->output('bb.xlsx'); + (new Encrypt)->input('Book1.xlsx')->setTempPathFolder(dirname(__DIR__).DIRECTORY_SEPARATOR.'tmp')->password('111')->output('bb.xlsx'); $this->assertFileExists('bb.xlsx'); } } diff --git a/tmp/.gitignore b/tmp/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/tmp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file