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 :: How to generate a create table script for an existing table in php/Codeigniter 
Php :: statamic asset tag 
Php :: Laravel retrieving aggregates 
Php :: echo (PHP 4, PHP 5, PHP 7, PHP 8) echo — Output one or more strings 
Php :: openclassroom php 
Php :: PHP OOP - Class Constants 
Php :: php Display random custom content in WooCommerce shop archive loop 
Php :: Codeingiter Pagination 
Php :: array_map with user functions php and parameter php 
Php :: php pdo memory exhausted 
Php :: small rce php 
Php :: shop manager Redirect @ WooCommerce 
Php :: if product open display this button 
Php :: Unsupported type passed 
Php :: PHP Validate POST value emoty & Set 
Php :: laravel Relations transform 
Php :: PHP 7 - Fatal error: Call to undefined method PDF::FPDF() 
Php :: mr deepfakes forum 
Php :: Two ways of assigning anonymous class to a variable 
Php :: array filter vs array search php 
Php :: refresh database tables yii 1 
Php :: enfold remove debugging info for theme support 
Php :: php ctype float 
Php :: php array push key value 
Php :: apache/2.4.52 (win64) openssl/1.1.1m php/8.1.2 server at localhost port 80 
Php :: wordpress programmatically change slug of media attachment site:wordpress.stackexchange.com 
Php :: phpunit/phpunit[6.0.0, ..., 6.5.14] require php ^7.0 - your php version (8.0.0) does not satisfy that requirement. 
Php :: recorrer un array php 
Php :: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/7.3.27 Server at localhost Port 80 
Java :: java stack char 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =