Tuesday 1 December 2015

Remove all characters and spaces form string in php

Remove all characters and spaces form string in php


 $string = 'name @123&';
 
echo preg_replace('/[^A-Za-z0-9\-]/', '', $string)

Friday 21 August 2015

Multiple File Upload by using Jquery

Multiple File Upload by using Jquery
 
View
<div id="maindiv">
<div id="formdiv">
<h2>Multiple Image Upload Form</h2>
<form enctype="multipart/form-data" action="" method="post">

<div id="filediv"><input name="file[]" type="file" id="file"/></div>
<input type="button" id="add_more" class="upload" value="Add More Files"/>
<input type="submit" value="Upload File" name="submit" id="upload" class="upload"/>
</form>


</div>
</div>

Controller

if($this->input->post('submit'))
{
$filename=$_FILES["file"]["name"];
$temp_file=$_FILES["file"]["tmp_name"];
$Temp_File_Type=$temp_file[0];
if($_FILES["file"]["size"][0] !=0)
{
$type1 = exif_imagetype($Temp_File_Type);

if ($type1 == 1 || $type1 == 2 || $type1 == 3 || $type1 == 6 ) // 1 =GIF, 2 =JPEG, 3 =PNG, 6 =BMP
{
for($i=0; $i<count($filename); $i++)
        {
            $File_Name=$filename[$i];
            $Temp_File=$temp_file[$i];
            $upload_path='temp_upload_images/'.$File_Name;
            move_uploaded_file($Temp_File, $upload_path);
        }
        echo "Image uploaded successfully";
}
}
}

Jquery Script
 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="script.js"></script>


<script>
var abc = 0;    
$(document).ready(function() {

$('#add_more').click(function() {
$(this).before($("<div/>", {
id: 'filediv'
}).fadeIn('slow').append($("<input/>", {
name: 'file[]',
type: 'file',
id: 'file'
}), $("<br/><br/>")));
});
// Following function will executes on change event of file input to select different file.
$('body').on('change', '#file', function() {
if (this.files && this.files[0]) {
abc += 1; // Incrementing global variable by 1.
var z = abc - 1;
var x = $(this).parent().find('#previewimg' + z).remove();
$(this).before("<div id='abcd" + abc + "' class='abcd'><img id='previewimg" + abc + "' src=''/></div>");
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
$(this).hide();
$("#abcd" + abc).append($("<img/>", {
id: 'img',
src: 'x',
alt: 'delete'
}).click(function() {
$(this).parent().parent().remove();
}));
}
});
// To Preview Image
function imageIsLoaded(e) {
$('#previewimg' + abc).attr('src', e.target.result);
};
$('#upload').click(function(e) {
var name = $(":file").val();
if (!name) {
alert("First Image Must Be Selected");
e.preventDefault();
}
});
});
</script>


CSS

<style>
#maindiv{
width:960px;
margin:10px auto;
padding:10px;
font-family:'Droid Sans',sans-serif
}
#formdiv{
width:500px;
float:left;
text-align:center
}
form{
padding:40px 20px;
box-shadow:0 0 10px;
border-radius:2px
}
h2{
margin-left:30px
}
.upload{
background-color:red;
border:1px solid red;
color:#fff;
border-radius:5px;
padding:10px;
text-shadow:1px 1px 0 green;
box-shadow:2px 2px 15px rgba(0,0,0,.75)
}
.upload:hover{
cursor:pointer;
background:#c20b0b;
border:1px solid #c20b0b;
box-shadow:0 0 5px rgba(0,0,0,.75)
}
#file{
color:green;
padding:5px;
border:1px dashed #123456;
background-color:#f9ffe5
}
#upload{
margin-left:45px
}
#noerror{
color:green;
text-align:left
}
#error{
color:red;
text-align:left
}
#img{
width:17px;
border:none;
height:17px;
margin-left:-20px;
margin-bottom:91px
}
.abcd{
text-align:center
}
.abcd img{
height:100px;
width:100px;
padding:5px;
border:1px solid #e8debd
}
b{
color:red
}
</style>

Pagination using Jquery in Codeigniter

Pagination using Jquery in Codeigniter


$page=3;
$page_count=10;
$data=array();
$content='<div class="pagiright">
                <ul>';
                if($page>2)
                {
                $content.='<li><a id="page-list" data-value=1>First</a></li>';
                }
                if($page!=1)
                {
                $content.='<li><a id="page-list" data-value='.($page-1).'> < </a></li>';
                }
                if(($page-2)>0)
                {
                $content.='<li><a id="page-list" data-value='.($page-2).'>'.($page-2).'</a></li>';
                }
                if(($page-1)>0)
                {
                $content.='<li><a id="page-list" data-value='.($page-1).'>'.($page-1).'</a></li>';
                }
                $content.='<li><a id="page-list" class="active" data-value='.($page).'> '.$page.' </a></li>';
               
                if(($page+1)<=$page_count)
                {
                $content.='<li><a id="page-list" data-value='.($page+1).'>'.($page+1).'</a></li>';
                }
                if(($page+2)<=$page_count)
                {
                $content.='<li><a id="page-list" data-value='.($page+2).'>'.($page+2).'</a></li>';
                }
                if($page<$page_count)
                {
                $content.='<li><a id="page-list" data-value='.($page+1).'> > </a></li>';
                }
                if($page<$page_count-1)
                {
                $content.='<li><a id="page-list" data-value='.$page_count.'>Last</a></li>';
                }
                $content.='</ul>
            </div>';
            $data['text']=$content;
            $this->load->view('holidays/pagi',$data);
           
CSS

<style>
.pagiright{width: 450px;
    float: left;}
    .pagiright ul{    margin: 0;
    padding: 0;
    float: right;
}
.pagiright li{list-style: none;
    float: left;
    margin-right: 8px;
    cursor: pointer;
    background: none!important;
    border: none!important;
    padding: 0!important;}
    .pagiright li a{text-decoration: none;
    color: #727272;
    font: 12px Arial,Helvetica,sans-serif;
    padding: 5px 12px;
    text-align: center;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    background: #f6f6f6;
    border: 1px solid #e3e3e3;}
.pagiright li a:hover {
    background: #F28D51;
    color: #fff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 1px solid #e3e3e3;
}
.pagiright li a.active {
    background: #FF5E00;
    color: #fff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 1px solid #E75222;
}
</style>

Jquery

$.post('controller',{'room_data':rooms},function(data){
   
    location="<?=base_url()?>holidays/holidayInfo/";
    });

Tuesday 7 July 2015

Codeigniter

Codeigniter

Controller

public function __construct(){
    
     parent::__construct();
   
     $this->load->model('admin_model');
     $this->class = strtolower(__CLASS__);
     $this->page_limit = 20;                        // Setting the number of records per page for Pagination
     $this->load->helper(array('url','form'));
     $this->load->library(array('form_validation','session','parser','pagination'));
   
      $this->load->library("excel");
   
   }


Model:

class Agent_model extends CI_Model{
  
       public function __construct(){
        
         $this->load->database();
       }
}

Thursday 2 July 2015

Upload CSV file in php

Upload CSV file

             $File_Name=$_FILES['upload']['tmp_name'];

                $fp=fopen($File_Name,'r');

                while($data=fgetcsv($fp))
                {
                    $add_data=array('Name'=>$data[0],'No_of_Nights'=>$data[1])

                 }

Monday 27 April 2015

get Php, codeigniter versions

echo phpinfo() --- Php information

CI_VERSION ---- codeigniter version