0

Im trying to upload an audio/mp3 document (15mb), that generates the following error "The file must be a file of type: mpga". When I upload other document audio/mp3 (7mb), the error does not appear.

In the validation:

$validator = Validator::make($request->all(), [
                    'name' => 'required|string|max:255',
                    'file' => 'required|mimes:mpga'
                ]);

in php.ini

upload_max_filesize=25M
max_file_uploads=25
post_max_size=25M

More info about two files:

The first Document (error)

Illuminate\Http\UploadedFile {#414
  -test: false
  -originalName: "bondad (1).mp3"
  -mimeType: "audio/mp3"
  -size: 4734618
  -error: 0
  #hashName: null
  path: "C:\xampp\tmp"
  filename: "php208F.tmp"
  basename: "php208F.tmp"
  pathname: "C:\xampp\tmp\php208F.tmp"
  extension: "tmp"
  realPath: "C:\xampp\tmp\php208F.tmp"
  aTime: 2017-12-19 13:53:30
  mTime: 2017-12-19 13:53:30
  cTime: 2017-12-19 13:53:30
  inode: 0
  size: 4734618
  perms: 0100666
  owner: 0
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  linkTarget: "C:\xampp\tmp\php208F.tmp"
}

The second document (Ok)

-test: false
  -originalName: "10 minutos de meditacion respirando.mp3"
  -mimeType: "audio/mp3"
  -size: 14418620
  -error: 0
  #hashName: null
  path: "C:\xampp\tmp"
  filename: "phpBFBB.tmp"
  basename: "phpBFBB.tmp"
  pathname: "C:\xampp\tmp\phpBFBB.tmp"
  extension: "tmp"
  realPath: "C:\xampp\tmp\phpBFBB.tmp"
  aTime: 2017-12-19 13:55:16
  mTime: 2017-12-19 13:55:16
  cTime: 2017-12-19 13:55:16
  inode: 0
  size: 14418620
  perms: 0100666
  owner: 0
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  linkTarget: "C:\xampp\tmp\phpBFBB.tmp"
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
Angel Prieto
  • 43
  • 1
  • 7
  • i've found the answer in this post: https://stackoverflow.com/questions/39594854/why-does-laravels-getmimetype-method-identify-a-file-as-application-octet-st – Angel Prieto Dec 20 '17 at 11:43

2 Answers2

1

It might depend on what is exactly in mp3 file. I think better solution might be using:

mimes:mp3

instead of:

mimes:mpga

or you can combine multiple mimes like so:

mimes:mpga,mp3
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
0

You can use mimetypes validation rule to match mime types, here is an example:

$validator = Validator::make($request->all(), [
    'name' => 'required|string|max:255',
    'file' => 'required|mimetypes:audio/mp3,application/octet-stream'
]);

Hope this hepls

YouneL
  • 8,152
  • 2
  • 28
  • 50