30 January 2009

Include a file and store contents to variable using output buffer

ob_start(); // start buffer
include ("file-to-include.php");
$content = ob_get_contents(); // assign buffer contents to variable
ob_end_clean(); // end buffer and remove buffer contents
echo $content;

22 January 2009

Function to create Watermark on Image

function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile, $hheight=0, $wwidth=0) {
list($width, $height) = getimagesize($SourceFile);
$image_p = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image_p, 255, 255, 255);
imagefill($image_p, 0, 0, $white);
$image = imagecreatefromjpeg($SourceFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
$black = imagecolorallocatealpha($image_p, 255, 255, 255, 100);

$font = 'arial.ttf';
$font_size = 20;
imagettftext($image_p, $font_size, 0, 0, 30, $white, $font, $WaterMarkText);
//imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $WaterMarkText);
if ($DestinationFile<>'') {
imagejpeg ($image_p, $DestinationFile, 100);
} else {
header('Content-Type: image/jpeg');
imagejpeg($image_p, null, 100);
};
imagedestroy($image);
imagedestroy($image_p);
}

16 January 2009

PHP Code to Read/Write XML Data


//=============reading xml request ======================

$HTTP_RAW_POST_DATA = $GLOBALS['HTTP_RAW_POST_DATA'];
//echo $HTTP_RAW_POST_DATA; exit;

$handle=fopen('data.xml','w');
fwrite($handle,$HTTP_RAW_POST_DATA);
fclose($handle);

$xml = simplexml_load_file("request.xml");
$UserName = $xml->attributes()->UserName;
$Password = $xml->attributes()->Password;
$PropertyCode = $xml->attributes()->PropertyCode;
$Function = $xml->Function;

//============writing xml output ==============

//MAKE SURE THAT extension=php_xmlrpc.dll is enabled
//;extension=php_domxml.dll must be commented

ob_start();
$doc = new DomDocument('1.0' , 'UTF-8');
$root = $doc->createElement('Response');
$occ = $doc->createElement('Website');

$occ = $root->appendChild($occ);
$occ->setAttribute('Name', 'name');
$occ->setAttribute('PropertyCode', '12345678');
$root = $doc->appendChild($root);

$child = $doc->createElement('Function');
$child = $root->appendChild($child);
$value = $doc->createTextNode('Function 2');
$value = $child->appendChild($value);

// get completed xml document
header("Content-type: text/xml");
$xml_string = $doc->saveXML();
echo $xml_string;
?>

13 January 2009

Template of 'Peer Feedback form'

Time , punctuality

Ability to learn and adopt new things

spontaneous on resposibility

Helping nature

Spontaneous on taking any action

Innovative thinking

07 January 2009

.htaccess to set settings in php.ini

Options +FollowSymLinks
RewriteEngine On

# Uncomment following line if your webserver's URL
# is not directly related to physival file paths.
# Update YourMamboDirectory (just / for root)

# RewriteBase /YourMamboDirectory

#
# Rules
#

php_flag register_globals on