Skip to content

Commit 076c979

Browse files
committed
Merge branch 'guessed-extension' into 7.x
2 parents 8aa0659 + d26be90 commit 076c979

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Illuminate/Filesystem/Filesystem.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Contracts\Filesystem\FileNotFoundException;
88
use Illuminate\Support\Traits\Macroable;
99
use Symfony\Component\Finder\Finder;
10+
use Symfony\Component\Mime\MimeTypes;
1011

1112
class Filesystem
1213
{
@@ -312,6 +313,17 @@ public function extension($path)
312313
return pathinfo($path, PATHINFO_EXTENSION);
313314
}
314315

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+
315327
/**
316328
* Get the file type of a given file.
317329
*

0 commit comments

Comments
 (0)