Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Open file to check type

Author Dave Jarvis <email>
Date 2026-02-08 19:35:22 GMT-0800
Commit d1020aaa92e3d9099b78ab2203adfd04b5f025c0
Parent d39aa00
new/File.php
private function isMediaType(string $type): bool {
- return str_contains(MediaTypeSniffer::isMediaType('', $this->name), $type);
+ $data = '';
+
+ // Only attempt to read if it's not a directory and the file exists locally
+ if (!$this->isDir && file_exists($this->name)) {
+ $handle = @fopen($this->name, 'rb');
+ if ($handle) {
+ // Read the first 12 bytes as expected by the Sniffer
+ $read = fread($handle, 12);
+ if ($read !== false) {
+ $data = $read;
+ }
+ fclose($handle);
+ }
+ }
+
+ return str_contains(MediaTypeSniffer::isMediaType($data, $this->name), $type);
}
Delta 16 lines added, 1 line removed, 15-line increase