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 :: laravel list get x amount in a collection 
Php :: sql update views +1 
Php :: load more data on button click in laravel 
Php :: if ( $post_armi-have_posts() ) { while ($post_armi-have_posts() ) { $post_armi-the_post(); 
Php :: phpmaker check master details page 
Php :: PhpDebugBar is not defined nginx 
Php :: wordpress ftp functions.php 
Php :: Failed to open stream: No such file or directory in /home/southsah/public_html/wp-content/advanced-cache.php on line 22 
Php :: skäller västgötaspetsar 
Php :: how to search like username,email and phone number in php 
Php :: woocommerce subscriptions custom user rolde 
Php :: Fehler beim Uploadtest der ausgewählten Datei. 
Php :: laravel vu3 
Php :: Dein Benutzer-Profil um weitere Social Media Accounts erweitern 
Php :: open two files at once in phpstrom 
Php :: what is the fee/commission charge for payoneer 
Php :: Drupal 9 how to pass arguments to custom blocks 
Php :: woocommerce affiliate product link image to external link 
Php :: php strom key 2 
Php :: php artisan insert user in database with tinker 
Php :: wc php free shipping function 
Php :: str_ireplace — Case-insensitive version 
Php :: JsonResource::withoutWrapping 
Php :: php 5.6 xampp 
Php :: current tab active on page reload in php 
Php :: laravel request allFiles 
Php :: detect change in log file in real time php 
Php :: php cgi file not fount linux 
Php :: laravel add model to one to many relationship 
Php :: laravel rename file if exists 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =