Author: Poria

PHp developer having fun with PHP and its frameworks Laravel,cakePHP and CodeIgniter

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]........)
         }

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 !

Run a URL from command prompt without opening browser – windows

Here are the steps :

1) Download wget from http://gnuwin32.sourceforge.net/packages/wget.htm

2) Paste the following and change the url

 "C:\Program Files (x86)\GnuWin32\bin\wget.exe" http://www.google.com

“C:\Program Files (x86)\GnuWin32\bin\wget.exe” is the path of wget executable file, you don’t need to type the full path if you defined path variable already.
You can simply do

 wget http://www.google.com

In case you are doing task scheduling , then create a file and paste the code from step 2, save file as xyz.bat and select this file as trigger in task scheduler.

options-permalink.php not found error 404 – wordpress

If there are no issues in your .htaccess.
If you have tried everything and it is not working… try

/wp-admin/includes/misc.php

Line 16 it will be

 function got_mod_rewrite() { to function got_mod_rewrite() {return true;

Line 42 it will be

 function got_url_rewrite() { to function got_url_rewrite() {return true;

Setting up first route,view,controller and sending data to view laravel 5

Example Route

<?php
Route::get('home','HomeController@index');  // you tell if url has /home then home controller index function handles that
?>

Then Controller will be
app/Http/Controllers/HomeController.php

<?php
namespace App\Http\Controllers;
class HomeController extends Controller
{
	//this is the funtion handling the /home
	public function index(){
		$data = "abc"; // here is sample data
	    return View::make('home/myhome', array('data' => $data));  // this is html file will be saved in views/home/myhome.blade.php
	}

}
?>

resources/views/home/myhome.blade.php

{{ $data }}