How to Display Confirm box when clicking a Link?

Confirm box is more useful to confirm the user action like while deleting data, we can easily set confirm box to a link with onclick attribute and little JavaScript. Look at the following example,i am sure you will easily get it to your projects .

    <a href="something.html" onclick="return confirm('Are you Sure you want to do this Action!');">Some Link</a>

HTML5 Force Download

In html5 we can easily set up force download with attribute called download, just check out the fallowing markup. the download attribute allows you to set separate name to download with actual(same) link point extension

<a href="link_to_download" download="set new name to download">Html5 download</a>

How to Get Width and Height of The Image Using PHP?

In PHP there is a built in function to get Image Width and Height, its Called getimagesize(),By Using this function we can get the width, height, type of an image and also attribute of an image
Just check out this Script and Change image Name to your Image name and check it !

<?php 
       $image = 'images/mypic.jpg'; //set image path here
	   list($width, $height, $type, $attr) = getimagesize($image);
	   echo $width; // ect...
?>

How to Get full web page URL from address bar with php?

In this Tutorial We are Going to get full URL of The Current viewing page from the Address Bar , its Really Easy and simple. Just see the Bellow Script

<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>

Yii Framework Basic Tutorial

Yii is Open Source PHP Framework. Qiang Xue is the founder of yii, He started the development of this open source framework on January 1st, 2008.

What is Yii?

  • Yii is fast and Easy,efficient and secure framework
  • Yii is great tool kit for developing Web 2.0 applications.
  • Great documented PHP framework

Why Yii?

  • Yii is Open Source ,Free to Use
  • Yii is Well Documented
  • Yii is High Performance
  • Yii comes with caching, authentication and role-based access control, scaffolding, testing, etc
  • Minimum Development Time compared to other
  • Yii is Secure and efficient

Where You Can Get Yii?

You can Download Yii at : http://www.yiiframework.com/

Yii features:

Wikipedia: Yii Features

  • Model-View-Controller (MVC) design pattern.
  • Database Access Objects (DAO), query builder, Active Record and database migration.
  • Integration with jQuery.
  • Form input and validation.
  • Ajax-enabled widgets, such as auto-complete input field, tree view, and so on.
  • Built-in authentication support. It also supports authorization via hierarchical role-based access control (RBAC).
  • Skinning and theming.
  • Automatic generation of complex WSDL service specifications and management of Web service request handling.
  • Internationalization and localization (I18N and L10N). It supports message translation, date and time formatting, number formatting, and interface localization.
  • Layered caching scheme. It supports data caching, page caching, fragment caching and dynamic content. The storage medium of caching can be changed.
  • Error handling and logging. Errors are handled and presented more nicely, and log messages can be categorized, filtered and routed to different destinations.
  • Security measures include cross-site scripting (XSS) prevention, cross-site request forgery (CSRF) prevention, cookie tampering prevention, etc.
  • Unit and functionality testing based on PHPUnit and Selenium.
  • Automatic code generation for the skeleton application, CRUD applications, etc.
  • Code generated by Yii components and command line tools complies to the XHTML standard.
  • Carefully designed to work well with third-party code. For example, it’s possible to use code from PEAR or Zend Framework in a Yii application.

How to Flush the DNS cache ?

Flush dns to get a new nameserver resolution for a domain .Rebooting will flush your cache. but there is an easier way.

To flush DNS  cache in Windows (Win XP, Win ME, Win 2000, vista, windows7):-
– Start -> Run -> type cmd
– in command prompt, type ipconfig /flushdns
– Done! You Window DNS cache has just been flush.
To flush the DNS cache in Linux

– To restart the nscd daemon, type /etc/rc.d/init.d/nscd  or /etc/init.d/nscd restart in your terminal
– This will flush dns cache in linux machine
To flush the DNS cache in Mac OS
– type lookupd -flushcache in your terminal to flush the DNS resolver cache.
ex: bash-2.05a$ lookupd -flushcache
– Once you run the command your DNS cache (in Mac OS X) will flush.

To flush the DNS cache in Mac OS X Leopard
– type dscacheutil -flushcache in your terminal to flush the DNS resolver cache. 
ex: bash-2.05a$ dscacheutil -flushcache
- Once you run the command your DNS cache (in Mac OS X Leopard) will flush.

Enquiry From with CodeIgniter?

This article will show and explain to you , how to create simple Enquiry Form in CodeIgniter. In this Example we will have a Form with Name , E-Mail ID, Phone Number, Enquiry fields. Here in this example we use codeIgniter Form helper[$this->load->helper(‘form’)] and CI Form Validation Library [$this->load->library(‘form_validation’)].

First Create A Form :[application/views/enquiry_view.php]

<?php 
$name = array('name' => 'name','id' => 'nameID','value' => set_value('name'));
$email = array('name' => 'email','id' => 'emailID','value' => set_value('email'));
$phone = array('name' => 'phone','id' => 'phoneID','value' => set_value('phone'));
$enquiry = array('name' => 'enquiry','id' => 'enquiryID','value' => set_value('enquiry'));
 
echo form_open();
 
echo form_label('Name','name');
echo form_input($name);
echo form_error('name');
echo br();
echo form_label('Email ID','email');
echo form_input($email);
echo form_error('email');
echo br();
echo form_label('Phone No.','Phone');
echo form_input($phone);
echo form_error('phone');
echo br();
echo form_label('Enquiry','enquiry');
echo form_textarea($enquiry);
echo form_error('enquiry');
echo br();
echo form_submit('submit','submit');
 
echo form_close();
?>

Create a Controller application/controllers/enquiry.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Enquiry extends CI_Controller {
 
	public function index()
	{
		$this->load->helper(array('form','url'));
		$this->load->library(array('form_validation'));
		// set validation Rules
		$this->form_validation->set_rules('name', 'name', 'required|trim|');
		$this->form_validation->set_rules('email', 'email', 'required|valid_email|trim');
		$this->form_validation->set_rules('phone', 'phone', 'required|trim|callback__validate_phone_number');
		$this->form_validation->set_rules('enquiry', 'enquiry', 'required|trim');		
		// check for validation result
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->view('enquiry_view');
		}
		else
		{
			// load CI Email Libray 
			$this->load->library('email');
			// store form data to variables
			$this->data['name'] = $this->input->post('name');
			$this->data['email'] = $this->input->post('email');
			$this->data['phone'] = $this->input->post('phone');
			$this->data['enquiry'] = $this->input->post('enquiry');
			$this->data['subject'] = 'Enquriy Form';
 
 
			$this->email->from('arjunphp@gmail.com', 'Arjun Anaparthi');
			$this->email->to('arjunphp@gmail.com');
			//$this->email->cc('');
			//$this->email->bcc('');
 
			$this->email->subject($this->data['subject']);
		$this->email->message($this->load->view('enquiry_email_html', $this->data, TRUE));
		//$this->email->set_alt_message($this->load->view('enquiry_email_text', $this->data, TRUE));
 
			if($this->email->send()) {
				echo 'Email sent';
			}
 
		}
	}
 
	function _validate_phone_number($value) {
	$value = trim($value);
	$match = '/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/';
	$replace = '/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/';
	$return = '($1) $2-$3';
    if (preg_match($match, $value)) {
    	return preg_replace($replace, $return, $value);
    } else {
    	$this->form_validation->set_message('_validate_phone_number', 'Invalid Phone.');
	return false;
    }
}
 
}
 
/* End of file enquiry.php */
/* Location: ./application/controllers/enquiry.php */

Create a file for html Email in views [application/views/enquiry_email_html.php]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $subject; ?></title>
</head>
 
<body>
<table border="0" cellspacing="3" cellpadding="3">
  <tr>
    <th scope="col">Name</th>
    <th scope="col">Email</th>
    <th scope="col">Phone</th>
    <th scope="col">Enquiry</th>
  </tr>
  <tr>
    <td><?php echo $name; ?></td>
    <td><?php echo $email; ?></td>
    <td><?php echo $phone; ?></td>
    <td><?php echo $enquiry; ?></td>
  </tr>
</table>
</body>
</html>

Set Email Configation Setting,you can set email setting Globally in CodeIgniter, to set crate a file email.php file in Config folder,

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
 
/*
| -------------------------------------------------------------------------
| Email
| -------------------------------------------------------------------------
| This file lets you define parameters for sending emails.
| Please see the user guide for info:
|
|	http://codeigniter.com/user_guide/libraries/email.html
|
*/
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
 
 
/* End of file email.php */
/* Location: ./application/config/email.php */

Thats it ! Thank You!

Please don’t forget to share and subscribe to latest updates of the blog. Also any comments and feedback are all welcome!

Twitter Type like Login Box with Jquery and CSS?

Here is the simple tutorial About Twitter Like Login Box Show and Hide effect with JQuery, You can achieve this with less lines of code Using JQuery Events, and require some css to give styles.

Html Code :

<div id="singin"><a href="#">signin</a></div>
<div id="signin_menu" style="display:none">
  <form action="" id="signin" method="post">
    <p class="textbox">
      <label for="username">Username or email</label>
      <input id="username" name="name" value="" title="username" tabindex="4" type="text">
    </p>
    <p class="textbox">
      <label for="password">Password</label>
      <input id="password" name="password" value="" title="password" tabindex="5" type="password">
    </p>
    <p class="remember">
      <input id="signin_submit" value="Sign in" tabindex="7" type="submit">
      <input id="remember" name="remember_me" value="1" tabindex="6" type="checkbox">
      <label for="remember">Remember me</label>
    </p>
    <p class="linkp"><a href="#">Forgot password?</a> </p>
    <p class="linkp"><a href="#">Forgot username?</a> </p>
    <p class="linkp"><a href="#">Already using Twitter on your phone?</a> </p>
  </form>
</div>

Css Code :

<style type="text/css">
#singin {
	background:none repeat scroll 0 0 #7FB3CC;
	color:#FFFFFF;
	font-weight:bold;
	margin-left:4px;
	padding:5px 6px 6px;
	width:100px;
	text-align:center;
}
#singin a {
	color:#2277BB;
	text-decoration:none;
}
#signin p {
    margin:0;
	color:#2277BB;
}
#signin .textbox label {
	display:block;
	padding:0 0 3px;
}
#signin_menu {
	-moz-border-radius:5px 0 5px 5px;
	-moz-box-shadow:0 3px 3px rgba(0, 0, 0, 0.3);
	background:none repeat scroll 0 0 #FFFFFF;
	border:5px solid #CCCCCC;
	line-height:16px;
	padding:8px;
	text-align:left;
	width:230px;
	z-index:100;
}
.box {
	display:block;
	font-size:11px;
    color:#666666;
}
.linkp {
	font-size:10px;
	color:#2277BB;
}
</style>;

jQuery code:

$(document).ready(function() { 
 
$('#singin').click(function(event){ 
event.preventDefault(); 
$('#signin_menu').toggle(); 
$('#singin').toggleClass('.box');
return false; });	
$('#signin_menu').mouseup(function() {
return false }); 
$(document).mouseup(function(){ 
$('#signin_menu').hide();
}); 
}); 
</script>

Please don’t forget to share and subscribe to latest updates of the blog. Also any comments and feedback are all welcome!
Thanks!

Uploading PDF files with CodeIgniter ?

CodeIgniter is a PHP framework, CodeIgniter has a number of helpers and libraries , which will reduce the development time and we can write more reliable and bugs free Code. Here ,This post is about uploading files in CodeIgniter, CodeIgniter has upload library , by using this Class we can upload files on server very easily

For Uploading a file as usually we need a Simple HTML from, with a input field and submit button.

here is the code :

<?php 
 echo $error;
 echo form_open_multipart('arjun/do_upload');
 echo form_input(array('type' => 'file','name' => 'userfile'));
 echo form_submit('submit','upload'); 
 echo form_close(); 
 ?>

NOw, in you Controller method , you need to set some config settings like uploading path, allowed types, upload size, width, height……ect..

    function do_upload()
	{
		// load codeigniter helpers
		$this->load->helper(array('form','url'));
		// set path to store uploaded files
		$config['upload_path'] = './uploads/';
		// set allowed file types
		$config['allowed_types'] = 'pdf';
		// set upload limit, set 0 for no limit
		$config['max_size']	= 0;
 
		// load upload library with custom config settings
		$this->load->library('upload', $config);
 
		 // if upload failed , display errors
		if (!$this->upload->do_upload())
		{
			$this->data['error'] = $this->upload->display_errors();
		     $this->data['page_data'] = 'admin/upload_view';
		     $this->load->view('admin/admin', $this->data);
		 }
		else
		{
			  print_r($this->upload->data());
			 // print uploaded file data
		}
	}

if you need to upload large files, you need to increase Max file uploading limit in php.ini on your server, you can increase upload limit with htaccess.

The file type you are attempting to upload is not allowed. PDF file uploading in CodeIgniter

if you see “The filetype you are attempting to upload is not allowed” error while uploading pdf files, just go to config/mines.php file open it and change the bellow line

'pdf'	=>	array('application/pdf', 'application/x-download'),

to

'pdf' => array('application/pdf', 'application/x-pdf', 'application/x-download', 'binary/octet-stream', 'application/unknown', 'application/force-download'),

How to Centre a DIV Block Using CSS?

This post is About Centering A div Block Using Css, To Center a Div Block , you need to set left-margin and right-margin
either in pixels or em or percentage units.

For example if you have a div with class name container, set the margin to container left and right sides auto, set the container with to 1000px ,This horizontally centers the element(container div) with respect to the edges of the container block.

<html>
<head>
<style>
body {
	/* IE-6 hack */
	text-align: center;
	/*some browsers add margins and padding by default, remove them*/
	padding: 0px;
	margin: 0px;
	color: #fff;
}
div#container {
	/* reset text centering*/
	text-align: left;
	margin-left: auto;
	margin-right: auto;
	margin-top: 0px;
	margin-bottom: 0px;
	width: 100px;
	background: #000;
}
</style>
</head>
<body>
<div id="container">
  <p>Hello World </p>
</div>
</body>
</html>
You might also likeclose