Skip to content

Commit 0be5126

Browse files
author
Jonas Quinten
committed
fix: rewind() and fseek() do not work for ftp
1 parent 949b200 commit 0be5126

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Remote/FtpFile.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,27 @@ public function rename(string $newPath): bool
5959

6060
return $success;
6161
}
62+
63+
/**
64+
* @return false|string
65+
*/
66+
public function getContent(): bool|string
67+
{
68+
$pointerLocation = ftell($this->fileHandle);
69+
if (false === $pointerLocation) {
70+
throw new \RuntimeException('unable to get current location of the file pointer. exception thrown to prevent unpredictable pointer jumping');
71+
}
72+
73+
$this->openStream($this->filePath, $this->mode);
74+
75+
$content = stream_get_contents($this->fileHandle);
76+
77+
$this->openStream($this->filePath, $this->mode);
78+
79+
if ($pointerLocation > 0) {
80+
$this->fread($pointerLocation);
81+
}
82+
83+
return $content;
84+
}
6285
}

0 commit comments

Comments
 (0)