Mick79's avatar

"File Not Found" after upload

I am using Spatie Simple Excel but it cannot find the file that I am passing to it. Here is my controller

  $path = $request->file('file')->storeAs('public/csvs', 'contacts.csv');

        // $rows is an instance of Illuminate\Support\LazyCollection
        $rows = SimpleExcelReader::create($path, 'csv')->getRows();

        $rows->each(function (array $rowProperties) {
            dd($rowProperties);
            // in the first pass $rowProperties will contain
            // ['email' => '[email protected]', 'first_name' => 'john']
        });

if I DD out $path I get public/csvs/contacts.csv and if I look in my local folders I can see the file is there.. well its actually in public/storage/csvs/contacts.csv but I think thats just how laravel works.

Any ideas?

0 likes
9 replies
Snapey's avatar

I'm confused

You say cannot find the file

then you say you can see the file and its in storage/app/public/csvs

Mick79's avatar

@Snapey Yeah sorry. Badly worded. The APP is saying "file not found". Thats the error message I'm getting.

But if I look with my own eyes I can see it.

Snapey's avatar
Snapey
Best Answer
Level 122

I assume SimpleExcelReader needs the full path so just prefix with storage_path

$rows = SimpleExcelReader::create(storage_path('app/') . $path, 'csv')->getRows();
1 like
Mick79's avatar

@Snapey It annoys me how smart you are.

Thank you so much. Adding storage_path was the key.

Snapey's avatar

why does your error say avon and your question csvs?

Mick79's avatar

@Snapey Sorry I was messing about with different directory names.

Please or to participate in this conversation.