Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel Read CSV File

 if (!empty($request->files) && $request->hasFile('csv_file')) {
                $file = $request->file('csv_file');
                $type = $file->getClientOriginalExtension();
                $real_path = $file->getRealPath();
                if ($type <> 'csv') {
                    Alert::error('Wrong file extension', 'Only CSV is allowed')->persistent('close');
                    return redirect()->back();
                }
                $data = $this->readCSV($real_path, array('delimiter' => ','));
            }
Comment

laravel import data from csv

function csvToArray($filename = '', $delimiter = ',')
{
    if (!file_exists($filename) || !is_readable($filename))
        return false;

    $header = null;
    $data = array();
    if (($handle = fopen($filename, 'r')) !== false)
    {
        while (($row = fgetcsv($handle, 1000, $delimiter)) !== false)
        {
            if (!$header)
                $header = $row;
            else
                $data[] = array_combine($header, $row);
        }
        fclose($handle);
    }

    return $data;
}
Comment

PREVIOUS NEXT
Code Example
Php :: omnipay capture 
Php :: comment acceder à la base de données phpmyadmin sur mac ave 
Php :: php curl fail verbosly 
Php :: PHP vsprintf — Return a formatted string 
Php :: exceptions on fatals(2) 
Php :: laravel belongsto with condition date 
Php :: php curl upload linkedin image 
Php :: appserviceprovider laravel share common settings for all controllers 
Php :: php pop up message 
Php :: getIP php 
Php :: execcommand insert video 
Php :: wordpress get posts by multiple authors 
Php :: firebase php curl 
Php :: wordpress auto save draft 
Php :: how to increase wp mailster attachment size 
Php :: Prevent infinite loop when saving Statamic entry 
Php :: condition for both of one should be true laravel eloquent 
Php :: Parameters inside Laravel localized string 
Php :: wordpress session variables 
Php :: download xampp php 5.3 for windows 7 64 bit 
Php :: undefined array key php 
Php :: php options list view sidebar (240 x 500), list view results (600 x 180), listing page (450 x 200) 
Php :: cmd download file from url 
Php :: Laravel Deployment to google cloud app engine flexible environment app.yaml file 
Php :: php git pull webhook 
Php :: replace key name in associative array 
Php :: Drupal 9 loop term objects to retrieve term data (id, name, uuid) 
Php :: laravel DomPDF live preview 
Php :: Explicit Octal numeral notation - PHP 8.1 
Php :: update query in laravel eloquent 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =