Monday, November 2, 2020

SERVER FORCE HTTP to HTTPS

 Add this script inside .htaccess file to force https.


RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Monday, July 20, 2020

CODEIGNITER IMAGE AUTO ROTATE WHEN UPLOAD USING MOBILE

I have a project that can upload image. During I upload an image using desktop, the image if fine. But if I upload an image using my phone, the image will rotated automatically.

Solution

1) You need to add a new library.The library automatically rotates the provided image based on the embedded EXIF data. I use it in my projects to correctly display images uploaded from mobile devices

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* @file application/libraries/Image_autorotate.php
*/
class Image_autorotate
{
    function __construct($params = NULL) {
    
        if (!is_array($params) || empty($params)) return FALSE;
        
        $filepath = $params['filepath'];
        $exif = @exif_read_data($filepath);
        
        if (empty($exif['Orientation'])) return FALSE;
        
        $CI =& get_instance();
        $CI->load->library('image_lib');
        
        $config['image_library'= 'gd2';
        $config['source_image'= $filepath;
        
        $oris = array();
        
        switch($exif['Orientation'])
        {
        case 1// no need to perform any changes
        break;

        case 2// horizontal flip
        $oris[] = 'hor';
        break;
                                        
        case 3// 180 rotate left
        $oris[] = '180';
        break;
                            
        case 4// vertical flip
        $oris[] = 'ver';
        break;
                        
        case 5// vertical flip + 90 rotate right
        $oris[] = 'ver';
        $oris[] = '270';
        break;
                        
        case 6// 90 rotate right
        $oris[] = '270';
        break;
                        
        case 7// horizontal flip + 90 rotate right
        $oris[] = 'hor';
        $oris[] = '270';
        break;
                        
        case 8// 90 rotate left
        $oris[] = '90';
        break;
        
        defaultbreak;
        }
        
        foreach ($oris as $ori) {
        $config['rotation_angle'= $ori;
        $CI->image_lib->initialize($config);
        $CI->image_lib->rotate();
        }
    }
}
// END class Image_autorotate
/* End of file Image_autorotate.php */
/* Location: ./application/libraries/Image_autorotate.php */
Place this file inside library folder.

2)  call this library after you have upload an image.

$imageinfo = $this->upload->data();
$full_path = $imageinfo['full_path'];

// check EXIF and autorotate if needed
$this->load->library('image_autorotate', array('filepath' => $full_path));


Reference :-

Saturday, April 25, 2020

CodeIgniter PHP : Merge Array

There are condition when we have two array and want to combine them. In PHP, we can use function array_merge() to merge those to array.
Below is the example how to use the function.


<?php
    $a1=array("a"=>"red","b"=>"green");
    $a2=array("c"=>"blue","b"=>"yellow");
    print_r(array_merge($a1,$a2));
?>

Result :
Array ([a]=>red [b]=>yellow [c]=>blue)

As you can see there are two value for key=b. But the result is going to print the 2nd array array as the value.

IONIC PASS PARAMETER

 To pass parameter to next page, first we need to make sure that we have 2 pages which is page from and page to. In page from ts file, you h...