Month: April 2017

Import large CSV data via PHP

Importing large data may cause Memory problems or timeout problems, here is how to avoid these problems.

$file = $_FILES['file']['tmp_name'];
        $handle = fopen($file, "r");
        while (($row = fgetcsv($handle, 0, ",")) !== FALSE) {
            // $row contains all the columns in a line in csv
            // insert into students(column1..., column2..., column3....) values($row[0],$row[1],$row[2]........)
         }
Advertisements

Export large data to CSV via PHP

Exporting large data may cause Memory problems or timeout problems, here is how to avoid these problems.

$query = $this->db->query("select * from students where (DATE(order_date) between '$start' and '$end') ");
                $filename = "reports.csv";
                header('Content-type: application/csv');
                header('Content-Disposition: attachment; filename='.$filename);
                

                $fp = fopen('php://output', 'w');
                $fields = $query->list_fields();
                foreach($fields as $field){
                        $header[] = $field;
                }	
                fputcsv($fp, $header);
                
                foreach ($query->result_array() as $data) {
                        //$fp = fopen('php://output', 'a');
                        fputcsv($fp, $data);
                        
                 }
                fclose($fp);
                exit;

KML Files not working on Google Maps

Here is a list of problems that may be the cause of problem :

1) Kml Path – Double check the path of file and make sure the file exists.
2) Missing mime types – You need to check for “KML” or “KMZ” mime type, if they are defined there on your server, if they are not then add

   .kml   application/vnd.google-earth.kml+xml
   .kmz   application/vnd.google-earth.kmz

3) If none of above – The KML can’t be accessed since it’s on your local machine and google can’t access that since it doesn’t know how to get to localhost:8080

Hope it helps someone !