We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8aa0659 + d26be90 commit 076c979Copy full SHA for 076c979
src/Illuminate/Filesystem/Filesystem.php
@@ -7,6 +7,7 @@
7
use Illuminate\Contracts\Filesystem\FileNotFoundException;
8
use Illuminate\Support\Traits\Macroable;
9
use Symfony\Component\Finder\Finder;
10
+use Symfony\Component\Mime\MimeTypes;
11
12
class Filesystem
13
{
@@ -312,6 +313,17 @@ public function extension($path)
312
313
return pathinfo($path, PATHINFO_EXTENSION);
314
}
315
316
+ /**
317
+ * Guess the file extension from the mime-type of a given file.
318
+ *
319
+ * @param string $path
320
+ * @return string|null
321
+ */
322
+ public function guessExtension($path)
323
+ {
324
+ return (new MimeTypes)->getExtensions($this->mimeType($path))[0] ?? null;
325
+ }
326
+
327
/**
328
* Get the file type of a given file.
329
*
0 commit comments