How to change the timezone in CodeIgniter 3.1.6

date_default_timezone_set() function is used to sets the default timezone used by all date or time functions in core PHP, CodeIgniter etc. date_default_timezone_set(); date_default_timezone_set('Asia/Kolkata'); # Option-1: In case of CodeIgniter, we can set the default timezone in the application/config.php file In case of CodeIgniter, we can set the default timezone in the application/config.php file <?php defined('BASEPATH') … Continue reading How to change the timezone in CodeIgniter 3.1.6

Download File in php or codeigniter

Want to download file using php. Here is the sample code. By using it you can download the file in php. you can use it in Codeigniter Also. the function are tested in Codeigniter. So it will works file in Codeigniter.  Just Call the function, download_sample(); It will start Downloading the file. public function download_sample(){ … Continue reading Download File in php or codeigniter

Download File in php

Download File in php function. Force Download. Here, $filepath = File Full path, where the file exists. $filename = File name of the file , which have to download ,LIKE: file1.txt header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\";"); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filename)); ob_clean(); … Continue reading Download File in php

Undefined property $db in Codeigniter

Severity: Notice Message: Undefined property: CI::$db in codeigniter 3.16 Are you facing any notice saying Undefined property: Home::$db or something like this in your Codeigniter application? The reason behind the error Undefined property $db in Codeigniter arises because you didn’t load database library in your controller/method to use any function of it. This error also … Continue reading Undefined property $db in Codeigniter

Convert stdClass object to array in PHP

Convert stdClass object to array in PHP The easiest way is to JSON-encode your object and then decode it back to an array: $array = json_decode(json_encode($object), True); Or if you prefer, you can traverse the object manually, too: foreach ($object as $value)     $array[] = $value->post_id;