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 :: undefined offset: 7 in d:xamphtdocsphpfunctionfunction.php on line 137 
Php :: Include Or Require Multiple Files On 1 Line 
Php :: how to show arraylist in comma separated with last and in php 
Php :: laravel 7 factory tinker 
Php :: how to include page specific css in xphp smart header 
Php :: how to use pg_dropcluster 
Php :: how to select max write textarea value in php 
Php :: nginx phpmyadmin subdirectory 
Php :: rename matomo php 
Php :: php csv to multirow array $_FILES 
Php :: Validate checkboxes laravel 
Php :: wordpress widget categories edit 
Php :: joomla k2 api 
Php :: iterate collection laravel 
Php :: Check php and wordpress version before activation 
Php :: bring up the power shell console php 
Php :: code on editing an image in database in php 
Php :: how to change css during holidays with php or Javascript in wordpress 
Php :: preg match apache log file 
Php :: wordpress redirect attachment page to file 
Php :: controller run 
Php :: difference between guard and fillable laravel 
Php :: functions file erased wordpress 
Php :: how to access laragon phpmyadmin in local network 
Php :: How to make a custom helper function, available in every controller for Laravel 
Php :: passing data from controller to blade view laravel 
Php :: saber value ao escolher combobox php 
Php :: debugger not installed phpstorm 
Php :: php get list of months by year 
Php :: Writing a New Block for Cryptocurrency Blockchain 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =