remigis's avatar

Laravel don't accept .xlsx file uploads

When i try to upload image or some other file and do dd($request->all()) i get:

array:2 [
  "scanName" => "lt"
  "file" => Illuminate\Http\UploadedFile {#1419
    -test: false
    -originalName: "lt.png"
    -mimeType: "image/png"
    -error: 0
    #hashName: null
    path: "C:\wamp64\tmp"
    filename: "phpC43B.tmp"
    basename: "phpC43B.tmp"
    pathname: "C:\wamp64\tmp\phpC43B.tmp"
    extension: "tmp"
    realPath: "C:\wamp64\tmp\phpC43B.tmp"
    aTime: 2022-06-27 17:22:33
    mTime: 2022-06-27 17:22:33
    cTime: 2022-06-27 17:22:33
    inode: 23643898043891995
    size: 928
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\wamp64\tmp\phpC43B.tmp"
  }
]

it is all good here, but when i try to upload .xlsx file this is the result

array:2 [
  "scanName" => "RMAREU-2205-017"
  "file" => Illuminate\Http\UploadedFile {#1419
    -test: false
    -originalName: "RMAREU-2205-017.xlsx"
    -mimeType: "application/octet-stream"
    -error: 1
    #hashName: null
    path: ""
    filename: ""
    basename: ""
    pathname: ""
    extension: ""
    realPath: "C:\Users\remig\PhpstormProjects\teamworx\public"
    aTime: 1970-01-01 03:00:00
    mTime: 1970-01-01 03:00:00
    cTime: 1970-01-01 03:00:00
    inode: false
    size: false
    perms: 00
    owner: false
    group: false
    type: false
    writable: false
    readable: false
    executable: false
    file: false
    dir: false
    link: false
  }
]

validation looks like this

public function rules()
    {
        return [
            //'file' => 'required',
            'scanName' => 'required|string'
        ];
    }

and when i uncomment file field and upload .xlsx file i get this validation error.

XHRPOSThttp://teamworx.local/createNewItemScan
[HTTP/1.1 422 Unprocessable Content 399ms]

	
message	"The given data was invalid."
errors	Object { file: […] }
file	[ "The file failed to upload." ]
0	"The file failed to upload."
0 likes
7 replies
Sinnbeck's avatar

How are you uploading it? What is your dev setup? Windows? Php artisan serve?

remigis's avatar

I use https://github.com/safrazik/vue-file-agent

 uploadFiles: function () {
            this.$refs.vueFileAgent.upload(this.uploadUrl, this.uploadHeaders, this.fileRecordsForUpload, (fileData) => {
                let formData = new FormData();
                formData.append('scanName', this.removeExtension(fileData.file.name));
                formData.append('file', fileData.file);
                return formData;
            });
            this.fileRecordsForUpload = [];
Sinnbeck's avatar

@remigis ok. Sounds like it could a problem with that, and not laravel. Does it work if you upload it using a regular form?

remigis's avatar
<form enctype="multipart/form-data" method="post" action="{{route('createNewItemScan')}}">
                            @csrf
                            <input type="file" name='file'>
                            <input type="text" name='scanName'>
                            <input type="submit" value='go'>
                        </form>

Validation

        return [
            'file' => 'required',
            'scanName' => 'required|string'
        ];

Controller

 public function createNewItemScan(CreateNewItemScanRequest $request)
    {
        dd($request->all());
    }

Outpuit with xlsx file

array:3 [
  "_token" => "UFVagi3IkZXS5GmSw0ASJBokgfc1BbY0mr8YeQkT"
  "scanName" => "hhh"
  "file" => Illuminate\Http\UploadedFile {#1419
    -test: false
    -originalName: "RMAREU-2205-017.xlsx"
    -mimeType: "application/octet-stream"
    -error: 1
    #hashName: null
    path: ""
    filename: ""
    basename: ""
    pathname: ""
    extension: ""
    realPath: "C:\Users\remig\PhpstormProjects\teamworx\public"
    aTime: 1970-01-01 03:00:00
    mTime: 1970-01-01 03:00:00
    cTime: 1970-01-01 03:00:00
    inode: false
    size: false
    perms: 00
    owner: false
    group: false
    type: false
    writable: false
    readable: false
    executable: false
    file: false
    dir: false
    link: false
  }
]

Outpuit with png file

array:3 [
  "_token" => "UFVagi3IkZXS5GmSw0ASJBokgfc1BbY0mr8YeQkT"
  "scanName" => "dsefvsw"
  "file" => Illuminate\Http\UploadedFile {#1419
    -test: false
    -originalName: "lt.png"
    -mimeType: "image/png"
    -error: 0
    #hashName: null
    path: "C:\wamp64\tmp"
    filename: "phpAE5C.tmp"
    basename: "phpAE5C.tmp"
    pathname: "C:\wamp64\tmp\phpAE5C.tmp"
    extension: "tmp"
    realPath: "C:\wamp64\tmp\phpAE5C.tmp"
    aTime: 2022-06-27 18:23:37
    mTime: 2022-06-27 18:23:37
    cTime: 2022-06-27 18:23:37
    inode: 9570149208548650
    size: 928
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\wamp64\tmp\phpAE5C.tmp"
  }
]
remigis's avatar

I am stupid, I Increase post_max_size and forgot to increase upload_max_filesize in php.ini Thank You all.

1 like

Please or to participate in this conversation.