Photo Collage [PHP]


<?php if (!empty($entry['photos'])) {
?>
<div class="crispbx">
    <div class="crispcont1">

        <!-- <p> -->
        <?php 
            // echo "string";
            $i = 0;
            if (count($entry['photos']) <= 9) {
                $linhas = floor(count($entry['photos']) / 3);
                $resto = count($entry['photos']) % 3;

                $tam1h = '143px';
                $tam2h = '216.5px';
                $tam3h = '436px';
                                                            
                $tam1w = '32.8%';
                $tam2w = '49.2%';
                $tam3w = '99.1%';
                
            }
            $photoDiv .= '<div class="wall_photoboard">';
            $i = 1;
            foreach ($entry['photos'] as $path) {

                if ($i <= ($linhas * 3)) {
                    // $tamAtual = $tam1;

                    $tamAtual = $tam1w;
                    $tamAtualh = $tam1h;   

                } else {
                    if ($resto == 2) {
                        // $tamAtual = $tam2;

                        $tamAtual = $tam2w;
                        $tamAtualh = $tam2h;

                    } else 
                        // $tamAtual = $tam3;

                        $tamAtual = $tam3w;
                        $tamAtualh = $tam3h;

                }

                $margin = 'margin: 2px 0 0 2px';
                if (count($entry['photos']) == 1) {
                    $margin = 'margin: 0';
                    $tamAtualh = '100%';
                    $tamAtual = '100%';
                }
                $photoDiv .= '<a class="mid2wall" href="photo_detail.php?id=' . $path['id'] . '" ><img  style="width: ' . $tamAtual . '; height: ' . $tamAtualh . '; border-radius:px;' . $margin .';border:1px solid #ccc !important;"  src="uploads/' . $path['file'] . '"/></a>';
                $i++;
                if ($i >= 9 && count($entry['photos']) > 9) {
                    $photoDiv .= ' and ' . (count($entry['photos']) - 9) . ' more photos';
                    break;
                }

            }
            $photoDiv .= '</div>';

            echo $photoDiv;

            $photoDiv = '';

         ?>

Error reporting management snippets in php [dev/prod]

/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 *
 * You can load different configurations depending on your
 * current environment. Setting the environment also influences
 * things like logging and error reporting.
 *
 * This can be set to anything, but default usage is:
 *
 *     development
 *     testing
 *     production
 *
 * NOTE: If you change these, also change the error_reporting() code below
 */
	define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */
switch (ENVIRONMENT)
{
	case 'development':
		error_reporting(0);
		// error_reporting(-1);
		ini_set('display_errors', 1);
		ini_set('max_execution_time', -1);
	break;

	case 'testing':
	case 'production':
		ini_set('display_errors', 0);
		if (version_compare(PHP_VERSION, '5.3', '>='))
		{
			error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
		}
		else
		{
			error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
		}
	break;

	default:
		header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
		echo 'The application environment is not set correctly.';
		exit(1); // EXIT_ERROR
}

Price Calculation with php depending on tax and discount price and percentage


function priceCalc($price, $discount_price, $discount_percent, $id_tax = -1)
{
    // $baseTax = _s("shop-base-tax");
    // $priceType = _s("shop-base-price");

    $baseTax = 21;
    $priceType = 1;

    // $ci = & get_instance();
    // $ci->load->database();

    // if( $id_tax != -1 ){
    //     $ci->db->select('t.*')
    //         ->from("tax as t")        
    //         ->where("id_tax", $id_tax);    
    //     $query = $ci->db->get();
    //     $baseTax = $query->row()->value;
    // }

    // return var_dump($baseTax);

    // $baseTax = 15;

    $tax = $baseTax; /* == $data_tax->value ? $baseTax : $data_tax->value; */

    $result = new stdClass();
    $result->oldPrice =  $price;

    // return $result->oldPrice;

    if ($discount_price > 0) {
        //samotná hodnota daně
        $taxvalue = ($discount_price / 100) * $tax;

        if ($priceType) {
            $result->newPrice = $discount_price + $taxvalue;
        } else {
            $result->newPrice = $discount_price;
        }
        $result->switch = 1;
    } elseif ($discount_percent > 0) {
        //samotná hodnota daně
        // $taxvalue = ($price / 100) * $tax;
        $taxvalue = ($result->oldPrice / 100) * $tax;


        if ($priceType) {
        	$result->oldPrice = (( $tax + 100 ) / 100 ) * $price;
            // $result->newPrice = $price - ((($price + $taxvalue) / 100) * $discount_percent);
            $result->newPrice = $result->oldPrice - ( ($result->oldPrice / 100) * $discount_percent);
        } else {
            $result->newPrice = $price - (($price / 100) * $discount_percent);
        }

        $result->switch = 1;
    } else {
        //samotná hodnota daně
        // $taxvalue = ($price / 100) * $tax;
        $taxvalue = ($result->oldPrice / 100) * $tax;
        

        if ($priceType) {
        	$result->oldPrice = (( $tax + 100 ) / 100 ) * $price;
            // $result->newPrice = $price + $taxvalue;
            $result->newPrice = $result->oldPrice;
        } else {
            $result->newPrice = $price;
        }
        //        $result->newPrice = $price;
        $result->switch = 0;
    }
    //    $priceFormat = number_format(, 2);
    $priceRound = (int) round($result->newPrice);
    //    $priceReplace = str_replace(",", " ", $priceRound);
    $result->newPrice = $priceRound;

    return $result;
}

var_dump(priceCalc(3469,0,30));

MYSQL backup by command in php

add a xml file called database.xml and also folders sql/ and sql_zip/ and

add a php file call backupdb.php and paste this class snippet


	/**
	* Database Backup classed for all the db at once
	*/
	class DatabaseBackup
	{

		private $dbhost = '';
		private $dbuser = '';
		private $dbpass = '';

		public $connection = null;
		
		function __construct($dbhost = 'localhost',$dbuser = 'root',$dbpass = '')
		{
			$this->dbhost = $dbhost;
			$this->dbuser = $dbuser;
			$this->dbpass = $dbpass;

			$this->connection = mysqli_connect($this->dbhost, $this->dbuser ,$this->dbpass);

		}


		// export all single database recursively 
		public function exportAll($extract_type = 'sql', $path = 'sql/')
		{
			
			$res = mysqli_query($this->connection,"SHOW DATABASES");
			
			while ($row = mysqli_fetch_assoc($res)) {
			   
				$dbname = $row['Database'];   

				if($extract_type == 'zip'){
				 
				$backup_file = $dbname . date("Y-m-d-H-i-s") . '.sql.gz';
				$command = "mysqldump --opt 
							-h $this->dbhost 
							-u $this->dbuser $dbname 
							| gzip > sql_zip/$backup_file";

				system($command);
				}
				else {
					$backup_file = $dbname . date("Y-m-d-H-i-s") . '.sql';
				$command = "mysqldump --user=$this->dbuser --password=$this->dbpass --host=$this->dbhost $dbname  > sql/" . $backup_file;
				// return $command;

				exec($command);
				}



				$db[] = [

				 'filename' => $backup_file,
				 'dbname' 	=> $dbname

				];

				 
			}

			return $db;
		}

		// export all single database recursively and save log to xml
		public function dbToXMLRecord($file = null)
		{
			$dbs = $this->exportAll();

			$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><databases></databases>');

			$xml->addAttribute('version', '1.0');

			foreach ($dbs as $key => $db) {

				$item  =  $xml->addChild('item');
				$item->addChild('filename',$db['filename']);
				$item->addChild('dbname',$db['dbname']);

			
			}

			$databaseXML = fopen("databases.xml", "w") or die("Unable to open file!");
			
			fwrite($databaseXML, $xml->asXML());
			
			fclose($databaseXML);

			return $xml->asXML();
		
		}

		// import single db from xml recursively from xml file
		public function xmlToDBRecord($file = 'databases.xml')
		{
			$xmlDoc = new DOMDocument();
			$xmlDoc->load($file);
			$x = $xmlDoc->documentElement;

			$count = 1;

			foreach ($x->childNodes AS $items) {

				print_r($items->childNodes[1]->nodeValue);


				$res = mysqli_query($this->connection,"CREATE DATABASE IF NOT EXISTS ". $items->childNodes[1]->nodeValue);
				mysqli_query($this->connection,"USE ".$items->childNodes[1]->nodeValue);
				
				$command = "mysql -u $this->dbuser -p $this->dbpass < sql/". $items->childNodes[0]->nodeValue ;
				// return $res;

				exec($command,$output=array(),$worked);

				switch($worked){
				    case 0:
				        echo 'Import file <b>' .$items->childNodes[0]->nodeValue .'</b> successfully imported to database <b>' .$items->childNodes[1]->nodeValue .'</b>';
				        break;
				    case 1:
				        echo 'There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:<br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$items->childNodes[1]->nodeValue .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$this->dbuser .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$this->dbhost .'</b></td></tr><tr><td>MySQL Import Filename:</td><td><b>' .$items->childNodes[0]->nodeValue .'</b></td></tr></table>';
				        break;
				}
				
				echo $command . "<br>";

				$count++;
								
			}

			return $count;
		}

		// test import 
		public function tryImport()
		{
			$command = "mysql -u $this->dbuser -p $this->dbpass < sql/music2017-02-02-23-21-12.sql" ;
            return $command;
            exec($command);
		}

		// all database in one sql file and xml
		public function tryAllExport()
		{
			// return $extract_type;
			$res = mysqli_query($this->connection,"SHOW DATABASES");
			// return $res;

			$databases = '';
			while ($row = mysqli_fetch_assoc($res)) {

				$databases .= $row['Database'] . ' ';
				
			}

			// return $databases;

			$command = "mysqldump -u $this->dbuser -p $this->dbpass --databases $databases > all_backup_2.sql" ;
			// $command = "mysqldump -u $this->dbuser -p $this->dbpass --databases c9db cashmemo clientapi db_lms > all_backup.sql" ;

			// return $command;

			$command = "mysqldump -u $this->dbuser -p $this->dbpass --all-databases > alldb_backup2.sql" ;
            
            // exec($command);
            exec('mysqldump -u root -p --all-databases --skip-lock-tables > alldb.sql');
		}



	}

	$dbBackup = new DatabaseBackup();

	if(isset($_GET['type']) && ($_GET['type'] == 'zip')){
		var_dump($dbBackup->exportAll('zip'));
	}
	else if(isset($_GET['to']) && ($_GET['to'] == 'xml')){
			var_dump($dbBackup->dbToXMLRecord());
	}
	else if(isset($_GET['to']) && ($_GET['to'] == 'db')){
			var_dump($dbBackup->xmlToDBRecord());
			// var_dump($dbBackup->tryImport());
	}
	else if(isset($_GET['to']) && ($_GET['to'] == 'tryx')){
			// var_dump($dbBackup->xmlToDBRecord());
			var_dump($dbBackup->tryAllExport());
	}
	else{
		var_dump($dbBackup->exportAll());
	}

in the browser serve “http://localhost/backupdb.php?to=xml
// here
to=xml for export from db to individuals sql file and xml enty
to=tryx all in a single file and also xml entry
to=zip all sqls file to zip in the sql_zip folder
to=db import from xml entry from sql files to db
record are saved as sql files in the sql folder and sql_zip folder

Ajax Email Send in Codeigniter


// routes

$route['admin/objednavka/send_email'] = "backend/order/send_email";

// html 

<div class="row static-info">
    <div class="col-md-5 name"> Email: </div>
    <input id="user_email" type="hidden" name="user_email" value="getsolved@gmail.com">
</div>

<div class="row static-info">
    <div class="col-md-5 name"> Subject: </div>
    <input id="user_email_sub" type="text" name="user_email_sub" value="getsolved@gmail.com">
</div>

<div class="row static-info">
    <div class="col-md-5 name"> body: </div>
    <textarea id="user_email_body" type="text" name="user_email_body">
    </textarea>
</div>

<div class="row static-info">
    <div class="col-md-5 name"></div>
    <div class="col-md-5 value">  
        <button id="sendOrderEmail">Send Order Email</button>
    </div>
</div>

<div class="row static-info">
    <div class="col-md-5 name"></div>
    <div class="col-md-2" style="display: none;" id="loading">
       <img src="<?= base_url() ?>assets/backend/img/preloader.gif" width="100%">
    </div>
</div>

// jquery 

$("#sendOrderEmail").click(function () {

    var url = $(".url").val();
    var email = $('#user_email').val();
    var user_email_sub= $('#user_email_sub').val();
    var user_email_body= $('#user_email_body').val();

    // alert(email + email_type)
    $.ajax({
        url: url + "admin/objednavka/send_email",
        // url: url + "backend/order/send_email",
        type: 'post',
        data: { 
             'user_email_sub': user_email_sub,  
             'email': email, 
             'user_email_body': user_email_body 
        },
        dataType: 'json',
        beforeSend: function () {
            $("#loading").show();
        },
        success: function (json) {
            
            if (json.success) {
                alert('Email Successfully Sent')
            }
            $("#loading").hide();
            
        },
        error: function (request, status, error) {
            alert("Nepodařilo se změnit.");
            $("#loading").hide();
        }
    });
});

// controller
class Order extends Base_backend
{

    public function __construct()
    {
        parent::__construct();

        $this->load->library('layout');
        $this->layout->title('Objadnávka | Weboo Shop 2.0');
        $this->load->library('form_validation');

        $this->menuOpen->m_order = 1;
    }

    public function sendEmailBackend($to, $subject, $body)
    {
        $sender = $this->setting_model->get_setting("email", "sender", DEFAULT_LANG)->value;
        $senderName = $this->setting_model->get_setting("email", "sender-name", DEFAULT_LANG)->value;

        include_once APPPATH.'/libraries/phpmailer/PHPMailerAutoload.php';
        $mail = new PHPMailer;

        $mail->isSMTP();                            // Set mailer to use SMTP
        $mail->Host = _s("mail-server");            // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                     // Enable SMTP authentication
        $mail->Username = _s("mail-login");         // SMTP username
        $mail->Password = _s("mail-password");      // SMTP password
        $mail->SMTPSecure = 'ssl';                  // Enable TLS encryption, `ssl` also accepted
        $mail->Port = _s("mail-port");              // TCP port to connect to
        $mail->CharSet = 'UTF-8';
        
        $mail->setFrom(_s("mail-login"), $senderName);
        $mail->addAddress($to);     
        $mail->addReplyTo($sender, $senderName);

        $mail->isHTML(true);                         // Set email format to HTML

        $mail->Subject = $subject;
        $mail->Body = $body;
        $mail->AltBody = $body;
        $mail->send();

        return 1;
    }

    public function send_email()
    {
        $item = $_POST['email_type'];
        $email_text  = $this->b_order_model->get_email_text_by_status($item);

        $email = $_POST['email'];
        $user_email_sub= $_POST['user_email_sub'];
        $user_email_body = $_POST['user_email_body '];

        $status = $this->sendEmailBackend($email,$user_email_sub, $user_email_body );

        echo json_encode(['success' => 1,'status' => $status]);
    }
}

Multiple Image upload jquery plugin in codeigniter

business logic part
(in controller)


   public function edit($id)
    {
        $data['product'] = $this->b_product_model->get_product_detail_with_meta($id, DEFAULT_LANG);
        $data['product_master_img']=$this->b_product_model->get_product_master_image($id);
        $data['product_images']=$this->b_product_model->get_all_images_product_detail($id);
        $data['allkategory'] = $this->b_category_model->get_all_category(DEFAULT_LANG); //All kategorie
        $data['js_list'][] = 'edit_product.js';
        $data['js_list'][] = 'custom_file_upload.js';
        $data['js_to_load'] = array('edit_product.js','custom_file_upload.js');
        
        $this->menuOpen->m_product = 1;
        $this->menuOpen->m_product_all = 1;
        $data['menu'] = $this->menuOpen;
        // $this->layout->view('product/edit_revize2', $data);
        $this->layout->view('product/edit_product', $data);
    }


    /**
     * metoda pro editaci hodnot produktu
     * param id:produktu
     */
    public function edit_action()
    {
            $vystup=$this->b_product_model->update_product(DEFAULT_LANG_ID,DEFAULT_LANG);

        /**
         * vrací typ použitého tlačítk a( save,save and close , no save )
         */
            if($vystup==-1){
            redirect(base_url() . 'admin/produkty');
            }else{
            redirect(base_url() . 'admin/produkt/edit/'.$vystup);
            }
    }

html part …
(in view)

<div class="form-group">
    <label class="control-label col-md-3">Product Other Image</label>
    <div class="col-md-9">
        <div id="picture">
            <div style="display:table;">
                <div class="one-photo">
                    <input id="product_other_image[]" class="fileUpload upload" type="file" name="product_other_image[]" multiple/>
                    <div class="removePhoto">x</div>
                    <i class="fa fa-plus" style="    margin-top: 25px;"></i>
                    <div class="preview"></div>
                </div>

            </div>

            <div class="clear"></div>

        </div>

    </div>
</div>

create and external css

#picture {
    /*display: none;*/
    padding: 10px;
    /*/ / background: #d8d8d8;*/
    /*/ / max-height: 510 px;*/
    /*/ / overflow-y: auto;*/
}

.one-photo .fa-plus {
    margin-top: 35px !important;
    position: absolute;
    top: 25px;
    left: 45%;
}

.removePhoto {
    z-index: 100;
    position: absolute;
    text-align: right;
    margin-right: 5px;
    top: 5px;
    right: 5px;
}

.one-photo {
    text-align: center;
    color: #ccc;
    font-size: 13pt;
}
.one-photo {
    width: 130px;
    height: 130px;
    text-align: center;
    margin-top: 10px;
    border: 2px dashed #ccc;
    color: #ccc;
    font-size: 13pt;
    float: left;
    margin-right: 5px;
    margin-bottom: 5px;
    position: relative;
}

.fileUpload {
    z-index: 10;
    margin-top: 0px;
    opacity: 0;
    height: 100px;
    position: absolute;
}

.fileUpload {
    position: relative;
    overflow: hidden;
    margin: 10px;
}

.preview {
    position: absolute;
    float: left;
    margin-top: -122px;
    width: 130px;
    margin-left: -2px;
    height: 130px;
}

.preview img {
    width: 130px !important;
    height: 130px;
}

create and external javascript file … (assuming jquery and jquery-ui exists)


var nextIndex = 1;

function attachFileReader(fileInput)
{
  if (window.FileReader) {
    var reader = new FileReader();
    reader.onload = function (e) {
      if( $(fileInput).siblings('.preview').html() != "" ){
        // $(fileInput).siblings('.preview').html('');
        $(fileInput).siblings('.preview').html($('<img></img>').attr('src', e.target.result).width(100));
        return;
      }

      $(fileInput).siblings('.preview').append($('<img></img>').attr('src', e.target.result).width(100));
      /*and now add one more*/
      // nextIndex = $('#picture input[type="file"]').size() + 1;
      nextIndex = nextIndex + 1;
      var next = $('<div></div>').addClass('one-photo');
      var preview = $('<div></div>').addClass('preview');
      var icon = $('<i></i>').addClass('fa fa-plus');

      var input = $('<input></input>').attr('type', 'file').addClass('fileUpload').addClass('imageUploads').attr('data-index',nextIndex).attr('name', 'photo[]');
      
      
      var removeThisPicture = $('<div></div>').addClass('removePhoto').html('x').click(function (e)
      {
        if ($('#picture .one-photo').size() > 1) {
          
          if ($(this).parent('.one-photo').children('.preview').html() != "") {
          // if ($('#picture .one-photo .preview').html() != "") {
            // console.log($(this).parent('.one-photo').children('.preview').html());
            console.log($(this).tagName);
            e.preventDefault();
            next.remove();
          }
          
        }else{
          e.preventDefault();
          $('#imageUploads').val('');
          $('#picture').fadeOut(500);
          // $(".one-photo").hide();
        }
      });
      next.append(input);
      next.append(removeThisPicture);
      next.append(icon);
      next.append(preview);
      $(fileInput).parent('.one-photo').after(next);
      input.change(function () {
        attachFileReader(this);
      });
    };
    reader.readAsDataURL($(fileInput) [0].files[0]);
  } 
  else
  {
    var next = $('<div></div>').addClass('one-photo');
    var preview = $('<div></div>').addClass('preview');


    var input = $('<input></input>').attr('type', 'file').addClass('fileUpload').attr('name', 'photo[]');
      

      input.change(function () {
      attachFileReader(this);
    });
      var removeThisPicture = $('<div></div>').addClass('removePhoto').html('x').click(function (e)
      {
        if ($('#picture .one-photo').size() > 1) {
          
          if ($(this).parent('.one-photo').children('.preview').html() != "") {
          // if ($('#picture .one-photo .preview').html() != "") {
            // console.log($(this).parent('.one-photo').children('.preview').html());
            console.log($(this).tagName);
            e.preventDefault();
            next.remove();
          }
          
        }else{
          e.preventDefault();
          $('#imageUploads').val('');
          $('#picture').fadeOut(500);
          // $(".one-photo").hide();
        }
      });
    var icon = $('<i></i>').addClass('fa fa-plus');
    next.append(input);
    next.append(removeThisPicture);
    next.append(icon);
    next.append(preview);
    $(fileInput).parent('.one-photo').after(next);
  }
}

$(document).ready(function ()
{
  $('.removePhoto').click(function ()
  {
    $(this).parent('.one-photo').remove();
  });

  $('.fileUpload').change(function () {
      attachFileReader(this);
    });

});  

now server part php will upload each and every image to the folder..
(in model)


    public function update_product($langid, $lang)
    {
        $this->load->helper('text');


        /* již přiřazené kategorie */
         if(isset($_POST['product_category']) && $_POST['product_category'] != 'un'){
                $id_category = $_POST['product_category'];
         }
         $product_id = $this->input->post('id_product', TRUE);


        $this->product_other_image_upload($product_id, 0);

        return -1;
    }

    public function product_other_image_upload($idproduct, $jeimg = null)
    {
        $num = rand(0,1000);
        
        $sirkaimg = "";
        $vyskaimg = "";
        //get settings pro upload
        $lang = 'CZ';
        $data['general'] = $this->b_setting_model->get_general(DEFAULT_LANG);
        foreach ($data['general'] as $g) {
            if ($g->key == "thumbnail-width") {
                $sirkaimg = $g->value;
            }
            if ($g->key == "thumbnail-height") {
                $vyskaimg = $g->value;
            }
        }
        if (extension_loaded('gd') && function_exists('gd_info')) {
            echo "PHP GD library is installed on your web server";
        } else {
            echo "PHP GD library is NOT installed on your web server";
        }

        if ($_FILES["product_other_image"]["error"][0] == UPLOAD_ERR_OK) {

            $count = count($_FILES['product_other_image']['name']); 

            for($key = 0 ; $key product_thumb($num . $filename, $sirkaimg, $vyskaimg, $num . $filename);
                if ($jeimg == 1) {
                    $this->db->select('f.file_name,f.thumb_name')
                            ->from("file as f");
                    $this->db->where("id_product", $idproduct);
                    $img_kat = $this->db->get();
                    $img_kat_data = $img_kat->row();
                    if ($img_kat_data > 0) {
                        $file_produkt_image = array(
                            "id_file_type" => 'detail_img',
                            "id_product" => $idproduct,
                            "is_active" => 1,
                            "file_name" => "assets/produkt_images/" . $num . $filename,
                            "thumb_name" => "assets/produkt_thumb/" . $num . $filename,
                            "file_description" => 'prodcut other image',
                            "created_by" => 2,
                            'modified_by' => 2
                        );
                        $this->db->where("id_product", $idproduct);
                        $this->db->where("id_file_type", 'detail_img');
                        $this->db->update('file', $file_produkt_image);
                    } else {
                        $file_produkt_image = array(
                            "id_file_type" => 'detail_img',
                            "id_product" => $idproduct,
                            "is_active" => 1,
                            "file_name" => "assets/produkt_images/" . $num . $filename,
                            "thumb_name" => "assets/produkt_thumb/" . $num . $filename,
                            "file_description" => 'prodcut other image',
                            "created_by" => 2,
                            'modified_by' => 2
                        );
                        $this->db->insert('file', $file_produkt_image);
                    }
                } else {
                    $file_produkt_image = array(
                        "id_file_type" => 'detail_img',
                        "id_product" => $idproduct,
                        "is_active" => 1,
                        "file_name" => "assets/produkt_images/" . $num . $filename,
                        "thumb_name" => "assets/produkt_thumb/" . $num . $filename,
                        "file_description" => 'prodcut other image',
                        "created_by" => 2,
                        'modified_by' => 2
                    );
                    $this->db->insert('file', $file_produkt_image);
                }
            }
        }
    }