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 chain query builder 
Php :: deleted_at 
Php :: Print all before characters once string found | matched string return 
Php :: Laravel display the date the participation was created 
Php :: change php variable value in javascript 
Php :: laravel eloquent get current sequence value 
Php :: laravel faker realtext 
Php :: An expression was expected phpmyadmin 
Php :: laravel telescope redirect to localhost 
Php :: find_by model fuelphp 
Php :: php variable undefined inside function argument 
Php :: codeigniter pagination example 
Php :: shopware redirect ot homepage 
Php :: how to validate students who made payment in php and mysql 
Php :: php function return type self 
Php :: PHP how to skip file upload if file already exist 
Php :: build_Assoc 
Php :: configurar pagina html php para mobile 
Php :: php read textarea line by line 
Php :: Laravel eloquent tricks 
Php :: wp ajax error handling 
Php :: image upload in cake 2 
Php :: Laravel function to check if image exist or not 
Php :: how to pass javascript variable to php 
Php :: phpdoc array type 
Php :: doctrine findby regex 
Php :: RequestCriteria laravel 
Php :: how to color php text 
Php :: laravel-5-on-shared-hosting-wrong-public-path 
Php :: AUTO TRANSFER OF DATA FROM SYBASE TABLE TO PHPMYSQL TABLE 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =