Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 'File not found at path' when importing file on server while file_exists($path) returns true #1827

Closed
3 tasks done
mattias-persson opened this issue Oct 11, 2018 · 21 comments

Comments

@mattias-persson
Copy link

mattias-persson commented Oct 11, 2018

Prerequisites

  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.1.16
  • Laravel version: 5.7
  • Package version: 3.1.1

Description

When I try following the documentation on importing a file stored on the server, I get an Illuminate\Contracts\Filesystem\FileNotFoundException saying File not found at path: [path to file]. However, a file_exists($path); returns true.

Steps to Reproduce

  1. Install a fresh version of Laravel.
  2. Install Laravel Excel.
  3. Put your xlsx-file in the project folder, for example in the storage/app folder.
  4. Run php artisan make:import UsersImport --model=User.
  5. Add the following code to a route, command or somewhere you can run it:
use Maatwebsite\Excel\Facades\Excel;
use App\Imports\UsersImport;

Excel::import(new UsersImport, storage_path('app/test.xlsx'));
  1. Run the code.

Expected behavior:
According to the docs, the rows in the file should be imported to the users table.

Actual behavior:
Illuminate\Contracts\Filesystem\FileNotFoundException: File not found at path: [path]

@GlennM
Copy link
Contributor

GlennM commented Oct 11, 2018

@mattias-persson
Try this one instead:
Excel::import(new UsersImport, 'test.xlsx');

See Importing from default disk for more information how to deal with the files you'd like to import.

@mattias-persson
Copy link
Author

Ah, my bad. I missed that part of the docs. Thank you!

@Emha2403
Copy link

i have same trouble, :(

controller:

with('success', "Import data succesfull"); } } and My class or model: $row[0], 'nama_mahasiswa' => $row[1], 'jenis_kelamin' => $row[2], 'tanggal_lahir' => $row[3], ]); } } and the error: League \ Flysystem \ FileNotFoundException File not found at path: Mahasiswa.xlsx and: public function assertPresent($path) { if ($this->config->get('disable_asserts', false) === false && ! $this->has($path)) { throw new FileNotFoundException($path); } } whats wrong on my work :(

@Emha2403
Copy link

hmmm
controller
`<?php

namespace App\Http\Controllers\Admin;

use App\Model\Mahasiswa;
use App\Model\UsersImport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;
use App\Http\Requests;

class UserimController extends Controller
{
public function import()
{
Excel::import(new UsersImport, 'Mahasiswa.xlsx');

      return back()->with('success', "Import data succesfull");
    }
  }

`

class or model:
`<?php

namespace App\Model;

use App\Mahasiswa;
use Maatwebsite\Excel\Concerns\ToModel;
class UsersImport implements ToModel
{
/**

  • @param array $row

  • @return Mahasiswa|nul
    */

    public function model(array $row)
    {
    return new Mahasiswa([
    'npm' => $row[0],
    'nama_mahasiswa' => $row[1],
    'jenis_kelamin' => $row[2],
    'tanggal_lahir' => $row[3],
    ]);
    }
    }
    `

@Emha2403
Copy link

and this error

League \ Flysystem \ FileNotFoundException
File not found at path: Mahasiswa.xlsx

@Emha2403
Copy link

and my database is

image

@Emha2403
Copy link

@GlennM please help me :(

@Emha2403
Copy link

image

@GlennM
Copy link
Contributor

GlennM commented Oct 30, 2018

@GlennM please help me :(

@Emha2403 Please check the location of your file. It looks like the file you're trying to import is not at the right location.

You should be able to find the correct directory by checking which disk you're using and find the corresponding root path for that driver.

@williams-young
Copy link

williams-young commented Nov 6, 2018

hi, I meet the same question, and i am sure my file has been uploaded at the right url i using

@GlennM
Copy link
Contributor

GlennM commented Nov 6, 2018

hi, I meet the same question, and i am sure my file has been uploaded at the right url i using

@williams-young Could you please open a new issue (according to the issue template) mentioning all relevant information? Thanks!

@johnreginald
Copy link

This is not a bug. Put your excel file in "storage/app" folder. it use default disk config in config/filesystems.php

Check This Part of Documentation

@eddgarx17
Copy link

xxxxxxxxxxxxxxxxxxx\storage\app
el archivo excel debe ir en la siguiente ruta.

@GlennM
Copy link
Contributor

GlennM commented Nov 30, 2018

xxxxxxxxxxxxxxxxxxx\storage\app
el archivo excel debe ir en la siguiente ruta.

Please post any support related questions or comments in English please if you would like us to provide support.

@GlennM GlennM reopened this Nov 30, 2018
@GlennM GlennM closed this as completed Nov 30, 2018
@nickpoulos
Copy link

I understand that this behavior is documented, but again it just seems bizarre and unintuitive. If you pass it an absolute filePath that comes back as true from file_exists()....it should load. There seems to be many unnecessary "gotchas" with this package, even when trying to do very basic import operations.

I have a 4 column XLSX with 100 rows that I want to import into a collection. I've had to visit the forums for filePath issues, dates coming back as integers, and trying to figure out what the point of these generated XYZImport classes are when I am trying to import a small xlsx to a collection.

@mattias-persson
Copy link
Author

If you pass it an absolute filePath that comes back as true from file_exists()....it should load

I agree on this. Seems like it causes confusion for a lot of users.

@cptnk
Copy link

cptnk commented Feb 1, 2019

I agree on this being confusing.

Can't the documentation mention the default storage/app path? I know this is configurable and all but im pretty sure this would give users with less of a laravel knowledge an easier time.

@GlennM
Copy link
Contributor

GlennM commented Feb 4, 2019

I agree on this being confusing.

Can't the documentation mention the default storage/app path? I know this is configurable and all but im pretty sure this would give users with less of a laravel knowledge an easier time.

If you think the documentation lacks some information, you're always welcome to submit a pull request to the docs. You can do so by using the Help us improve this page! link located at the bottom of each page.

@vesper8
Copy link

vesper8 commented Mar 25, 2019

count me in with the confused.. was trying to pass an absolute path using base_path() since my files are stored outside the storage folder and in a special "modules" folder.. couldn't get it to work, finally had to move my files into the storage path. If the path received starts with a front slash it should just assume that it's an absolute path IMO

@mkantautas
Copy link

Yeah, actually it seems that even after adding files to storage it can't find it. Judging by the error response it's trying a relative path in the end 🤦‍♂️ .

@patrickbrouwers
Copy link
Member

It has been documented for a few months that using absolute paths is possible: https://docs.laravel-excel.com/3.1/imports/basics.html#importing-full-path

I'll lock this ticket to keep the support process streamlined. If new bugs or questions arise, please create a new issue explaining your specific case.

@SpartnerNL SpartnerNL locked as resolved and limited conversation to collaborators May 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests