fast-excel: Could not open file to import

I cannot read my imported file, here is my function:

 public function import(Request $request)
    {
        $products = (new FastExcel)->import($request->file('file'), function ($reader) {
            return Product::create([
                'title' => $reader['title'],
                'slug' => $reader['slug'],
                'imageOne' => $reader['imageOne'],
                'imageTwo' => $reader['imageTwo'],
                'imageThree' => $reader['imageThree'],
                'short_description' => $reader['short_description'],
                'description' => $reader['description'],
                'stock' => $reader['stock'],
                'price' => $reader['price'],
                'installation_price' => $reader['installation_price'],
                'meta_description' => $reader['meta_description'],
                'meta_tags' => $reader['meta_tags'],
                'discounted_price' => $reader['discounted_price'],
                'start_discounted' => $reader['start_discounted'],
                'end_discounted' => $reader['end_discounted'],
                'demo_link' => $reader['demo_link'],
                'status' => $reader['status'],
                'category_id' => $reader['category_id']
            ]);
        });

        Session::flash('success', 'Your products imported successfully.');
    }

error i get:

Could not open C:\Users\usename\AppData\Local\Temp\php32D9.tmp for reading! (Could not open C:\Users\usename\AppData\Local\Temp\php32D9.tmp for reading.)

PS: I have tried documents way: using return Product::create(['title' => $reader['title'],........ instead of foreach, `same result (same error).

any idea?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 24 (11 by maintainers)

Most upvoted comments

My code was wrong, could you try this:

 public function import(Request $request)
    {
        $path = $request->file('file')->store('excel-files');
        $products = (new FastExcel)->import(storage_path('app/' . $path), function ($reader) {
            return Product::create([
                'title' => $reader['title'],
                'slug' => $reader['slug'],
                'imageOne' => $reader['imageOne'],
                'imageTwo' => $reader['imageTwo'],
                'imageThree' => $reader['imageThree'],
                'short_description' => $reader['short_description'],
                'description' => $reader['description'],
                'stock' => $reader['stock'],
                'price' => $reader['price'],
                'installation_price' => $reader['installation_price'],
                'meta_description' => $reader['meta_description'],
                'meta_tags' => $reader['meta_tags'],
                'discounted_price' => $reader['discounted_price'],
                'start_discounted' => $reader['start_discounted'],
                'end_discounted' => $reader['end_discounted'],
                'demo_link' => $reader['demo_link'],
                'status' => $reader['status'],
                'category_id' => $reader['category_id']
            ]);
        });

        Session::flash('success', 'Your products imported successfully.');
    }

The only line I changed is this one:

$products = (new FastExcel)->import(storage_path('app/' . $path), function ($reader) {

It should work!

the code gives

Could not open for reading! File does not exist.

I also tried:

$path = "file:///C:/Users/username/Downloads/new/new-products.csv";

and i got the same error:

Could not open for reading! File does not exist.

as the result of saving my file to storage I have txt file in my storage folder included this content , , , , , ,

This issue is closed long time ago. But just in case somebody else will be coming accross it. I had the same error message “Couldn’t open for reading”. After trying with firstly save file on server and then open - I discovered that Large files were simply not saved. There was php_max_upload_filesize = 2MB on my server’s ini. Changed it to 2Gb and it started working very nice

File is stored properly and it exists. Maatwebexcel can read and handle that file but FastExcel can’t. It says:

Could not open the file …path + filename.xlsx for reading!

Path is under /storage/app/uploads/… but for maatweb I’m using just /uploads/date/… and it works, with this package not. I tried everything but I don’t know if it uses relative or abs path or some other conventions. BTW: I’m trying this package to see if it can handle a huge xlsx file for importing to the db faster and more effectively.

@robertnicjoo u can use base_path() for mayor control. https://laravel.com/docs/5.7/helpers#paths

@rap2hpoutre yeah,I finally go to use laravel-excel 2.1 version.

@robertnicjoo Sorry for late answer (vacations).

Could you test with this CSV file: https://github.com/rap2hpoutre/fast-excel/blob/master/tests/test2.csv? It’s the one used in my unit tests (and the unit tests actually works).

I tested your CSV (https://github.com/rap2hpoutre/fast-excel/blob/master/tests/test18.csv) and added a unit test (https://github.com/rap2hpoutre/fast-excel/blob/master/tests/FastExcelTest.php#L163) and it still works.

So, I don’t think it’s a problem about your CSV content.

I think the problem may be about your file extension. Could you rename your file to something.csv? And could you double check the uploaded file does exists in the folder you open?