1

I am trying to import data from excel file. when i upload .csv file using livewire it convert to .txt file.

note: I am not sure if it is from Livewire or Laravel.

here is my modal code for importing file:

<x-jet-modal maxWidth="sm" wire:model="showImportDialog">
    <form wire:submit.prevent="import" method="POST" enctype="multipart/form-data">
        <div>
            <div class="text-lg">Import Users</div>
        </div>
        <div>
            <input type="file" wire:model="users" name="users" id="users" />
        </div>
        <x-jet-button type="submit">Import</x-jet-button>
    </form>
</x-jet-modal>

and this is my livewire component:

...
use WithFileUploads;

public $users;

public function import()
{
    dd($this->users); // originalName: "W4K99h75YVHSou815dV0fErWMLzZ75-metaUUNTX1VzZXJzXzIwMjEtMDktMTQgMTdfNDdfNTMuY3N2-.txt"
    $validated = $this->validate([
        'users.*' => 'required|file|mimes:xls,xlsx,csv',
    ]);

    dd($validated); // it displays "[]"
}
...

when I dd() before validation shows this:

enter image description here

update 1:

when I did this:

dd($this->users->getClientOriginalName());

it shows:

Users_2021-09-14 17_47_53.csv

Update 2:

livewire config file:

enter image description here

2
  • can you provide the temporary_file_upload rules in config/livewire.php file? Commented Sep 15, 2021 at 7:00
  • @MdSomir thanks, I update the question and provided livewire config file. Commented Sep 15, 2021 at 7:03

1 Answer 1

1

Here is the explanation for this: How to store csv file laravel 5 php?

But basically, you have to specify the type of file using ->storeAs($path, $filename . '.csv'). Then laravel will save it like a CSV file; otherwise, it will turn the file into .txt.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.