Skip to content

Commit 6d50cf8

Browse files
committed
Implement saving support without dbase extension
Signed-off-by: Michal Čihař <[email protected]>
1 parent 1d66768 commit 6d50cf8

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/ShapeFile.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,17 @@ private function _loadRecords() {
349349
}
350350

351351
private function _saveRecords() {
352-
if (!ShapeFile::supports_dbase()) {
353-
return;
354-
}
355-
$dbf_name = $this->_getFilename('.dbf');
356-
if (file_exists($dbf_name)) {
357-
unlink($dbf_name);
358-
}
359-
$this->DBFFile = $this->_createDBFFile();
360-
if ($this->DBFFile === false) {
361-
return false;
352+
$do_dbase = ShapeFile::supports_dbase();
353+
354+
if ($do_dbase) {
355+
$dbf_name = $this->_getFilename('.dbf');
356+
if (file_exists($dbf_name)) {
357+
unlink($dbf_name);
358+
}
359+
$this->DBFFile = $this->_createDBFFile();
360+
if ($this->DBFFile === false) {
361+
return false;
362+
}
362363
}
363364

364365
$offset = 50;
@@ -373,7 +374,9 @@ private function _saveRecords() {
373374
$offset += (4 + $record->getContentLength());
374375
}
375376
}
376-
dbase_pack($this->DBFFile);
377+
if ($do_dbase) {
378+
dbase_pack($this->DBFFile);
379+
}
377380
}
378381

379382
private function _openFile($toWrite, $extension, $name) {

src/ShapeRecord.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ public function saveToFile(&$SHPFile, &$DBFFile, $recordNumber) {
168168
$this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType));
169169
break;
170170
}
171-
$this->_saveDBFData();
171+
if (ShapeFile::supports_dbase() && isset($this->DBFFile)) {
172+
$this->_saveDBFData();
173+
}
172174
}
173175

174176
public function updateDBFInfo($header) {

0 commit comments

Comments
 (0)