rashiqulrony/laravel-csv-import 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rashiqulrony/laravel-csv-import

最新稳定版本:v1.0.0

Composer 安装命令:

composer require 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

README 文档

README

License: MIT

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

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-01