lundi 9 mars 2020

Validate .tar file upload in Laravel 5.8

I have this code

$inputs    = Input::all();
$file      = Input::file('file');
$validator = Validator::make($request->all(), [
    'file' => 'required|max:50000|mimes:application/x-tar',
]);

if ($validator->fails()) {

    $messages = $validator->messages();
    dd($file,$messages); <<<< --- keep executing 


    return Redirect::to('/vnf-packages/create')->withErrors($validator)->withInput()
    ->with('error','Something is wrong with your upload image');
} else {
..
}

I don't know why it kept getting into the fail block. I did upload the file with .tar.

Am I missing anything in my codes ?


Updated

as you can see, I did upload the .tar file

dd($file,$messages);

UploadedFile {#446 ▼
  -test: false
  -originalName: "config-vnfp-vyos-567.tar"
  -mimeType: "application/x-tar"
  -error: 0
  #hashName: null
  path: "/private/var/tmp"
  filename: "phpNaZGxr"
  basename: "phpNaZGxr"
  pathname: "/private/var/tmp/phpNaZGxr"
  extension: ""
  realPath: "/private/var/tmp/phpNaZGxr"
  aTime: 2020-03-09 15:10:28
  mTime: 2020-03-09 15:10:28
  cTime: 2020-03-09 15:10:28
  inode: 14703131
  size: 140
  perms: 0100600
  owner: 70
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
}
MessageBag {#454 ▼
  #messages: array:1 [▼
    "file" => array:1 [▼
      0 => "The file must be a file of type: tar."
    ]
  ]
  #format: ":message"
}

Updated 2

'file' => 'required|max:50000|mimes:tar', //fail 
'file' => 'required|max:50000|mimes:application/x-tar', //fail 
'file' => 'required', //success 


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire