rashiqulrony / laravel-csv-import
Import Very Large CSV Without File Store and Chunk Upload system Laravel package to export and import CSV files in a memory-optimized way
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^7.0|^8.0
- laravel/framework: ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
This package is auto-updated.
Last update: 2025-07-02 06:06:20 UTC
README
A Laravel package to import large CSV files efficiently using chunked memory processing, on-the-fly UTF-8 conversion, and no temporary storage overhead.
๐ฆ Installation
Install via Composer:
composer require rashiqulrony/laravel-csv-import
If you're using Laravel <5.5 or your Laravel version doesn't support package auto-discovery, add the service provider manually:
// config/app.php 'providers' => [ Rashiqulrony\CSVImport\Providers\AppServiceProvider::class, ];
โ๏ธ Configuration
Publish the config file (optional):
php artisan vendor:publish --provider="Rashiqulrony\CSVImport\Providers\AppServiceProvider" --tag=config
This creates a file: config/csvimport.php
return [ 'chunk_size' => 200, // Number of rows to return per batch ];
๐ Usage
โ Basic Example
use Rashiqulrony\CSVImport; public function upload(Request $request) { $request->validate([ 'file' => 'required|file|mimes:csv', ]); $result = CSVImport::upload($request->file('file')); if (!empty($result) && is_array($result)) { foreach ($result as $key => $value) { foreach ($result[$key] as $data) { // Process or save the row (e.g. DB::table(...)->insert($row)) } } } else { return back()->with('error', 'Data not found or invalid file.'); } return back()->with('success', 'CSV imported successfully!'); }
๐ฅ Method: CSVImport::upload($file)
Returns | Description |
---|---|
array |
On success: returns a chunk of rows (associative arrays). |
['status' => false, 'message' => '...'] |
On failure. |
โ Features
- Detects and converts multiple encodings to UTF-8
- Skips invalid rows (missing fields, malformed headers)
- Efficient memory usage with chunking
- No need to manually store or manage temp files
๐งช Supported Encodings
- UTF-8
- UTF-16LE / UTF-16BE
- Windows-1252
- ISO-8859-1
๐ Directory Structure
laravel-csv-import/
โโโ src/
โ โโโ CSVImport.php
โ โโโ Providers/
โ โโโ AppServiceProvider.php
โโโ config/
โ โโโ csvimport.php
โโโ composer.json
โโโ README.md
๐ License
This package is open-sourced software licensed under the MIT license.
๐ค Author
Rashiqul Rony
๐ง rashiqulrony@gmail.com
๐ github.com/rashiqulrony