Monday 16 January 2017

Remove Image tag and html content from content in php


1.Actual Content with image 

$bodycontent = "<div id='testing'>Exmple body content and <img src=\"image/image.png\"/> image none.</div><div id='testing'>Exmple body content <img src=\"image/image.png\"/> image none.</div><div id='testing'>Exmple body content <img src=\"image/image.png\"/>image none.</div>";

2.Display only content in php tags

<?php
$bodycontent = preg_replace("/<img[^>]+\>/i", "", $bodycontent);
    $bodycontent = strip_tags($bodycontent);
  echo $bodycontent;
?>




Friday 24 June 2016

Upload Multiple Images in Codeigniter

1.Html Form

 <html>
 <head>
    <title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('photos/image_upload');?>
<input type="file" multiple name="userfile[]" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>

2.Controller Code

 function file_upload()
{      
    $this->load->library('upload');

    $files = $_FILES;
    $cpt = count($_FILES['userfile']['name']);
    for($i=0; $i<$cpt; $i++)
    {          
        $_FILES['userfile']['name']= $files['userfile']['name'][$i];
        $_FILES['userfile']['type']= $files['userfile']['type'][$i];
        $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
        $_FILES['userfile']['error']= $files['userfile']['error'][$i];
        $_FILES['userfile']['size']= $files['userfile']['size'][$i];  
        $this->upload->initialize($this->upload_config());
        $this->upload->do_upload();
    }
}

private function upload_config()
{  
    //upload an image options
    $config = array();
    $config['upload_path'] = './Images/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size']      = '0';
    $config['overwrite']     = FALSE;
    return $config;
}

Monday 7 March 2016

How to Upload base64 Encoded Image in Codeigniter





$image = base64_decode($this->input->post("image_base64_string"));
// decoding base64 string value
$image_name = md5(uniqid(rand(), true));// image name generating with random number with 32 characters
$filename = $image_name . '.' . 'png';
//rename file name with random number
$path = set_realpath('product/image/');
//image uploading folder path
file_put_contents($path . $filename, $image);
// image is bind and upload to respective folder

Sunday 2 August 2015

Program to find prime numbers in PHP

Program to find prime numbers in PHP

<?php
//Program to find prime numbers in php

$counts =19;

for( $a = 2; $a <= $counts; $a++ )
{
for( $s = 2; $s < $a; $s++ )
{
if( $a % $s == 0 )
{
break;
}

}
if( $s == $a )
echo “Prime Number : “, $a, “<br>”;
}
?>

HERE IS THE OUTPUT

Prime Number : 2
Prime Number : 3
Prime Number : 5
Prime Number : 7
Prime Number : 11
Prime Number : 13
Prime Number : 17
Prime Number : 19

Monday 13 April 2015

Difference Between Primary Key and Unique Key In Sql Server

Difference Between Primary Key and Unique Key In Sql Server


Both PRIMARY KEY and UNIQUE KEY enforces the Uniqueness of the values (exp: avoids duplicate values) on the columns on which it is defined.  Also these key’s can Uniquely identify each row in database table.

Here are some major difference between PRIMARY KEY and UNIQUE KEY:



PRIMARY KEY UNIQUE KEY
NULL It doesn’t allow Null values.
Because of this we refer
PRIMARY KEY = UNIQUE KEY + Not Null CONSTRAINT
Allows Null value. But only one Null value.
INDEX By default it adds a clustered index By default it adds a UNIQUE non-clustered index
LIMIT A table can have only one PRIMARY KEY Column[s] A table can have more than one UNIQUE Key Column[s]
CREATE SYNTAX Below is the sample example for defining a single column as a PRIMARY KEY column while creating a table:
CREATE TABLE dbo.Customer
(
Id INT NOT NULL PRIMARY KEY,
FirstName VARCHAR(100),
LastName VARCHAR(100),
City VARCHAR(50)
)
Below is the Sample example for defining multiple columns as PRIMARY KEY. It also shows how we can give name for the PRIMARY KEY:
CREATE TABLE dbo.Customer
(
Id INT NOT NULL,
FirstName VARCHAR(100) NOT NULL,
LastName VARCHAR(100),
City VARCHAR(50),
CONSTRAINT PK_CUSTOMER PRIMARY KEY (Id,FirstName)
)
Below is the sample example for defining a single column as a UNIQUE KEY column while creating a table:
CREATE TABLE dbo.Customer
(
Id INT NOT NULL UNIQUE,
FirstName VARCHAR(100),
LastName VARCHAR(100),
City VARCHAR(50)
)
Below is the Sample example for defining multiple columns as UNIQUE KEY. It also shows how we can give name for the UNIQUE KEY:
CREATE TABLE dbo.Customer
(
Id INT NOT NULL,
FirstName VARCHAR(100) NOT NULL,
LastName VARCHAR(100),
City VARCHAR(50),
CONSTRAINT UK_CUSTOMER UNIQUE (Id,FirstName)
)
ALTER SYNTAX Below is the Syntax for adding PRIMARY KEY CONSTRAINT on a column when the table is already created and doesn’t have any primary key:
ALTER TABLE dbo.Customer
ADD CONSTRAINT PK_CUSTOMER PRIMARY KEY (Id)
Below is the Syntax for adding UNIQUE KEY CONSTRAINT on a column when the table is already created:
ALTER TABLE dbo.Customer
ADD CONSTRAINT UK_CUSTOMER UNIQUE (Id)
DROP SYNTAX Below is the Syntax for dropping a PRIMARY KEY:
ALTER TABLE dbo.Customer
DROP CONSTRAINT PK_CUSTOMER
Below is the Syntax for dropping a UNIQUE KEY:
ALTER TABLE dbo.Customer
DROP CONSTRAINT UK_CUSTOMER

Difference Between Primary Key and Unique Key In Sql Server

Wednesday 8 April 2015

Display Loading Image While Page Loads

Display Loading Image While Page Loads

<html>
<body>
<div class="image_loader"></div>
<table>
<tr><td>Name :</td><td>Sharanu</td></tr>
<tr><td>Profile</td><td>Website Developer</td></tr>
</table>
</body>
</html>

<style>
.image_loader {
      width: 100%;
        height: 100%;
        z-index: 5;
        position: absolute;
background: url('images/loading.gif') 50% 50% no-repeat rgb(249,249,249);
}
</style>

//create image folder for storing the image to display as per the in css path and also you can download image from this url http://sierrafire.cr.usgs.gov/images/loading.gif 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(window).load(function() {
$(".image_loader").fadeOut("slow");
})
</script>

Friday 20 February 2015

Generate Excel Report in Codeigniter

Generate Excel Report in Codeigniter


1.Controller file its just for examplle

$data['excel_data'] = $this->excel_model->view();  (this value with array and in model you should be create view function)

2. View file


These 3 line for generate excel report those line should be top on the view file
<?php
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="DonationList.xls"');
header('Cache-Control: max-age=0');
?>
<table width="100%" border="1">
    <tr>
        <th>Id</th>
        <th>Donor Name</th>
</tr>
<?php foreach ($excel_data as $row): ?>
    <tr>
        <td><?php echo $row->id; ?></td>
        <td><?php echo $row->name; ?></td>
</tr>
</table>

once you run this type file in Codeigniter you get downloadable excel  sheet

Generate Excel Report in Codeigniter