-1

I had this

$file = array('file' => Input::file('file'));

and

dd($file); return

How do I access file mimeType via the Laravel way ?

code-8
  • 54,650
  • 106
  • 352
  • 604
  • try `$file->getClientMimeType()` or `$file->getMimeType()` [ref](https://stackoverflow.com/questions/39594854/why-does-laravels-getmimetype-method-identify-a-file-as-application-octet-st) – iamab.in Mar 09 '20 at 18:34
  • `Call to a member function getMimeType() on array` – code-8 Mar 09 '20 at 18:35
  • Someone that downvote my post, please explain why !, sO i can learn not to do it again. – code-8 Mar 09 '20 at 18:36
  • update `$file = array('file' => Input::file('file'));` to `$file = Input::file('file');` – iamab.in Mar 09 '20 at 18:38

2 Answers2

1

You can the mime type of the file retrieve it like this:

$file['file']->getMimeType();
Chin Leung
  • 14,621
  • 3
  • 34
  • 58
1

You may use one of this functions:

  • $file['file']->getClientMimeType();

    The client mime type is extracted from the request from which the file was uploaded, so it should not be considered as a safe value. For a trusted mime type, use getMimeType() instead (which guesses the mime type based on the file content).

  • $file['file']->getMimeType();

    The mime type is guessed using a MimeTypeGuesserInterface instance, which uses finfo_file() then the "file" system binary, depending on which of those are available.

Hafez Divandari
  • 8,381
  • 4
  • 46
  • 63