| 1 comments ]

function ByteSize($bytes)
{
$size = $bytes / 1024;
if($size < 1024)
{
$size = number_format($size, 2);
$size .= ' KB';
}else {
if($size / 1024 < 1024) {
$size = number_format($size / 1024, 2);
$size .= ' MB';
} else if($size / 1024 / 1024 < 1024) {
$size = number_format($size / 1024 / 1024, 2);
$size .= ' GB';
}
}
return $size;
}

| 0 comments ]

//This function is for sub directories size (This will retrn an array )
function du($location) {
if (!$location || !is_dir($location))
return 0;
$size = 0;
$files = 0;
$dirs = 0;

$all = opendir($location);
while ($file = readdir($all)) {
if (is_dir($location.'\\'.$file) and $file != ".." and $file != ".") {
$temp = du($location.'/'.$file);
$dirs++;
$size += $temp['size'];
$files += $temp['files'];
$dirs += $temp['dirs'];
unset($temp);
unset($file);
} elseif (!is_dir($location.'\\'.$file)) {
$stats = stat($location.'\\'.$file);
$size += $stats['size'];
$files++;
unset($file);
}
}
closedir($all);
unset($all);
return array('size' => $size, 'files' => $files, 'dirs' => $dirs);
}

| 0 comments ]

// This function shows the file size of aparticular
function show_dir($dir){
// global $totalsize;
$handle = @opendir($dir);
while ($file = @readdir($handle)){
$size=filesize($dir.$file);
$totalsize=$totalsize+$size;
}
@closedir($handle);
if($totalsize==8192){$totalsize=0;}
return($totalsize);
}

| 0 comments ]

function cropImage($picture,$fixedwidth,$fixedheight,$mogrify) {

// GET IMG
$img = imagecreatefromjpeg($picture);
$width= imagesx($img);
$height= imagesy($img);
// CROP WIDTH
if($width!=$fixedwidth){
$ratio =$fixedwidth/$width;
$NewHeight=round($height*$ratio);
$NewWidth=round($width*$ratio);
exec( $mogrify." -resize ".$NewWidth."x".$NewHeight."! $picture");
exec( $mogrify." -crop ".$fixedwidth."x".$fixedheight."+0+0 $picture");
// REFRESH
$img = imagecreatefromjpeg($picture);
$width= imagesx($img);
$height= imagesy($img);
}
// CROP HEIGHT
if($height!=$fixedheight){
$ratio =$fixedheight/$height;
$NewHeight=round($height*$ratio);
$NewWidth=round($width*$ratio);
exec( $mogrify." -resize ".$NewWidth."x".$NewHeight."! $picture");
exec( $mogrify." -crop ".$fixedwidth."x".$fixedheight."+0+0 $picture");
}
//
ImageDestroy($img);
}

| 0 comments ]

function getFileSizeW($filePath){
$blah = getimagesize($filePath);
$type = $blah['mime'];
$width = $blah[0];
return $width;}

function getFileSizeH($filePath){
$blah = getimagesize($filePath);
$type = $blah['mime'];
$height = $blah[1];
return $height;}

| 0 comments ]

function imageInfo($file = null, $out = null) {

// If $file is not supplied or is not a file, warn the user and return false.
if (is_null($file) || !is_file($file)) {
echo '

Warning: image_info() => first argument must be a file.

';
return false;
}

// Defines the keys we want instead of 0, 1, 2, 3, 'bits', 'channels', and 'mime'.
$redefine_keys = array(
'width',
'height',
'type',
'attr',
'bits',
'channels',
'mime',
);

// If $out is supplied, but is not a valid key, nullify it.
if (!is_null($out) && !in_array($out, $redefine_keys)) $out = null;

// Assign usefull values for the third index.
$types = array(
1 => 'GIF',
2 => 'JPG',
3 => 'PNG',
4 => 'SWF',
5 => 'PSD',
6 => 'BMP',
7 => 'TIFF(intel byte order)',
8 => 'TIFF(motorola byte order)',
9 => 'JPC',
10 => 'JP2',
11 => 'JPX',
12 => 'JB2',
13 => 'SWC',
14 => 'IFF',
15 => 'WBMP',
16 => 'XBM'
);
$temp = array();
$data = array();

// Get the image info using getimagesize().
// If $temp fails to populate, warn the user and return false.
if (!$temp = getimagesize($file)) {
echo '

Warning: image_info() => first argument must be an image.

';
return false;
}

// Get the values returned by getimagesize()
$temp = array_values($temp);

// Make an array using values from $redefine_keys as keys and values from $temp as values.
foreach ($temp AS $k => $v) {
$data[$redefine_keys[$k]] = $v;
}

// Make 'type' usefull.
$data['type'] = $types[$data['type']];

// Return the desired information.
return !is_null($out) ? $data[$out] : $data;
}

| 0 comments ]

function cropimage($picture,$fixedwidth,$fixedheight,$mogrify) {

// GET IMG
$img = imagecreatefromjpeg($picture);
$width= imagesx($img);
$height= imagesy($img);
// CROP WIDTH
if($width!=$fixedwidth){
$ratio =$fixedwidth/$width;
$NewHeight=round($height*$ratio);
$NewWidth=round($width*$ratio);
exec( $mogrify." -resize ".$NewWidth."x".$NewHeight."! $picture");
exec( $mogrify." -crop ".$fixedwidth."x".$fixedheight."+0+0 $picture");
// REFRESH
$img = imagecreatefromjpeg($picture);
$width= imagesx($img);
$height= imagesy($img);
}
// CROP HEIGHT
if($height!=$fixedheight){
$ratio =$fixedheight/$height;
$NewHeight=round($height*$ratio);
$NewWidth=round($width*$ratio);
exec( $mogrify." -resize ".$NewWidth."x".$NewHeight."! $picture");
exec( $mogrify." -crop ".$fixedwidth."x".$fixedheight."+0+0 $picture");
}
//
ImageDestroy($img);
}

?>

| 0 comments ]

function get_rnd_iv($iv_len){
$iv = '';
while ($iv_len-- > 0) {
$iv .= chr(mt_rand() & 0xff);
}
return $iv;
}
function md5Encrypt($plain_text, $password, $iv_len = 16){
$plain_text .= "\x13";
$n = strlen($plain_text);
if ($n % 16) $plain_text .= str_repeat("\0", 16 - ($n % 16));
$i = 0;
$enc_text = get_rnd_iv($iv_len);
$iv = substr($password ^ $enc_text, 0, 512);
while ($i < $n) {
$block = substr($plain_text, $i, 16) ^ pack('H*', md5($iv));
$enc_text .= $block;
$iv = substr($block . $iv, 0, 512) ^ $password;
$i += 16;
}
return base64_encode($enc_text);
}
function md5Decrypt($enc_text, $password, $iv_len = 16){
$enc_text = base64_decode($enc_text);
$n = strlen($enc_text);
$i = $iv_len;
$plain_text = '';
$iv = substr($password ^ substr($enc_text, 0, $iv_len), 0, 512);
while ($i < $n) {
$block = substr($enc_text, $i, 16);
$plain_text .= $block ^ pack('H*', md5($iv));
$iv = substr($block . $iv, 0, 512) ^ $password;
$i += 16;
}
return preg_replace('/\\x13\\x00*$/', '', $plain_text);
}
?>

| 0 comments ]

function flipImage($image, $vertical, $horizontal) {
$w = imagesx($image);
$h = imagesy($image);

if (!$vertical && !$horizontal) return $image;

$flipped = imagecreatetruecolor($w, $h);

if ($vertical) {
for ($y=0; $y<$h; $y++) {
imagecopy($flipped, $image, 0, $y, 0, $h - $y - 1, $w, 1);
}
}

if ($horizontal) {
if ($vertical) {
$image = $flipped;
$flipped = imagecreatetruecolor($w, $h);
}

for ($x=0; $x<$w; $x++) {
imagecopy($flipped, $image, $x, 0, $w - $x - 1, 0, 1, $h);
}
}

return $flipped;
}

| 0 comments ]

function createImage(){

// creates the images, writes the file
$fileRand = md5(rand(100000,999999));
$string_a = array("A","B","C","D","E","F","G","H","J","K",
"L","M","N","P","R","S","T","U","V","W","X","Y","Z",
"2","3","4","5","6","7","8","9");
$keys = array_rand($string_a, 6);
foreach($keys as $n=>$v){
$string .= $string_a[$v];
}
$backgroundimage = "security_background.gif";
$im=imagecreatefromgif($backgroundimage);
$colour = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
$font = 'Arial';
$angle = rand(-5,5);
// Add the text
imagettftext($im, 16, $angle, 15, 25, $colour, $font, $string);
$outfile= "$fileRand.gif";
imagegif($im,$outfile);
return $outfile;
}

//code for image display
echo "";

?>

| 0 comments ]

function randomFloat ($min,$max) {
return ($min+lcg_value()*(abs($max-$min)));
}

| 0 comments ]

function isNaN( $var ) {
return !ereg ("^[-]?[0-9]+([\.][0-9]+)?$", $var);
}

| 0 comments ]

function arabicToRomanNumerals($input_arabic_numeral='') {

if ($input_arabic_numeral == '') { $input_arabic_numeral = date("Y"); } // DEFAULT OUTPUT: THIS YEAR
$arabic_numeral = intval($input_arabic_numeral);
$arabic_numeral_text = "$arabic_numeral";
$arabic_numeral_length = strlen($arabic_numeral_text);

if (!ereg('[0-9]', $arabic_numeral_text)) {
return false; }

if ($arabic_numeral > 4999) {
return false; }

if ($arabic_numeral < 1) {
return false; }

if ($arabic_numeral_length > 4) {
return false; }

$roman_numeral_units = $roman_numeral_tens = $roman_numeral_hundreds = $roman_numeral_thousands = array();
$roman_numeral_units[0] = $roman_numeral_tens[0] = $roman_numeral_hundreds[0] = $roman_numeral_thousands[0] = ''; // NO ZEROS IN ROMAN NUMERALS

$roman_numeral_units[1]='I';
$roman_numeral_units[2]='II';
$roman_numeral_units[3]='III';
$roman_numeral_units[4]='IV';
$roman_numeral_units[5]='V';
$roman_numeral_units[6]='VI';
$roman_numeral_units[7]='VII';
$roman_numeral_units[8]='VIII';
$roman_numeral_units[9]='IX';

$roman_numeral_tens[1]='X';
$roman_numeral_tens[2]='XX';
$roman_numeral_tens[3]='XXX';
$roman_numeral_tens[4]='XL';
$roman_numeral_tens[5]='L';
$roman_numeral_tens[6]='LX';
$roman_numeral_tens[7]='LXX';
$roman_numeral_tens[8]='LXXX';
$roman_numeral_tens[9]='XC';

$roman_numeral_hundreds[1]='C';
$roman_numeral_hundreds[2]='CC';
$roman_numeral_hundreds[3]='CCC';
$roman_numeral_hundreds[4]='CD';
$roman_numeral_hundreds[5]='D';
$roman_numeral_hundreds[6]='DC';
$roman_numeral_hundreds[7]='DCC';
$roman_numeral_hundreds[8]='DCCC';
$roman_numeral_hundreds[9]='CM';

$roman_numeral_thousands[1]='M';
$roman_numeral_thousands[2]='MM';
$roman_numeral_thousands[3]='MMM';
$roman_numeral_thousands[4]='MMMM';

if ($arabic_numeral_length == 3) { $arabic_numeral_text = "0" . $arabic_numeral_text; }
if ($arabic_numeral_length == 2) { $arabic_numeral_text = "00" . $arabic_numeral_text; }
if ($arabic_numeral_length == 1) { $arabic_numeral_text = "000" . $arabic_numeral_text; }

$anu = substr($arabic_numeral_text, 3, 1);
$anx = substr($arabic_numeral_text, 2, 1);
$anc = substr($arabic_numeral_text, 1, 1);
$anm = substr($arabic_numeral_text, 0, 1);

$roman_numeral_text = $roman_numeral_thousands[$anm] . $roman_numeral_hundreds[$anc] . $roman_numeral_tens[$anx] . $roman_numeral_units[$anu];
return ($roman_numeral_text);
}

| 0 comments ]

#******************************************************************************
# This is a super-hard array conversion function.(PHP.net)
#******************************************************************************
#It only returns TRUE if the two arrays are completely identical, that means that
#they have the same keys, and the values of all keys are exactly the same (compared with ===)

function array_same($a1, $a2) {
if (!is_array($a1) || !is_array($a2))
return false;

$keys = array_merge(array_keys($a1), array_keys($a2));

foreach ($keys as $k) {
if (!isset($a2[$k]) || !isset($a1[$k]))
return false;

if (is_array($a1[$k]) || is_array($a2[$k])) {
if (!array_same($a1[$k], $a2[$k]))
return false;
}
else {
if (! ($a1[$k] === $a2[$k]))
return false;
}
}

return true;
}

#******************************************************************************

| 1 comments ]

#******************************************************************************
# function to generate unique key
#******************************************************************************
function generateUniqueKey($key)
{
if (strlen($key)>8) {
$key = $key[0] . $key[1] . $key[2];
}
$id = $key . '_';
$uid = uniqid();
$len = strlen($uid);
$max = (9 - strlen($key));
for ($c = $len; ; $c --) {
$id .= $uid[$c];
if ($c == ($len - $max)) {
break;
}
}
return $id;
}

#******************************************************************************

| 0 comments ]

#******************************************************************************
# function to find factorial
#******************************************************************************

function fact($i){
if($i==1){
return 1;
}else{
return $i*fact($i-1);
}
}

#******************************************************************************

| 0 comments ]

#******************************************************************************
# function to remove random underscore
#******************************************************************************

function removeUnderscore($string)
{

$result = str_replace("_"," ",$string);
return $result;

}

#******************************************************************************
# function to add random underscore
#******************************************************************************
function addUnderscore($string)
{

$result = str_replace(" ","_",$string);
return $result;

}
#******************************************************************************

| 0 comments ]

#******************************************************************************
# function to create random password
#******************************************************************************

function createRandomPassword() {

$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;

while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}

#******************************************************************************

| 0 comments ]

One of my Friend Created a class For Pagination in PHP . This class can be used to split MySQL database query listings between multiple pages.

It takes as parameters a SQL query, the limit number of result rows to display per page, and the number of the listing page being displayed.

The class executes the query to retrieve the results of the current page and stores the result handle in a class variable.

The class also generates HTML with links to go to the first, last, next, previous and any intermediate page of the listing.

It also generates HTML to display the current page being display and the total number of rows in the result set.

The links trigger the call of a Javascript function that will switch to the page associated with the link.

The PHP Class:

<?
/*
Developed by Reneesh T.K
reneeshtk@gmail.com
You can use it with out any worries...It is free for you..It will display the out put like:
First | Previous | 3 | 4 | 5 | 6 | 7| 8 | 9 | 10 | Next | Last
Page : 7 Of 10 . Total Records Found: 20
*/
class Pagination_class{
var $result;
var $anchors;
var $total;
function Pagination_class($qry,$starting,$recpage)
{
$rst = mysql_query($qry) or die(mysql_error());
$numrows = mysql_num_rows($rst);
$qry .= " limit $starting, $recpage";
$this->result = mysql_query($qry) or die(mysql_error());
$next = $starting+$recpage;
$var = ((intval($numrows/$recpage))-1)*$recpage;
$page_showing = intval($starting/$recpage)+1;
$total_page = ceil($numrows/$recpage);

if($numrows % $recpage != 0){
$last = ((intval($numrows/$recpage)))*$recpage;
}else{
$last = ((intval($numrows/$recpage))-1)*$recpage;
}
$previous = $starting-$recpage;
if($previous < 0){
$anc = "First | Previous | ";
}else{
$anc .= "<a href='javascript:pagination(0);'>First | </a>";
$anc .= "<a href='javascript:pagination($previous);'>Previous | </a>";
}

################If you dont want the numbers just comment this block###############
$norepeat = 4;//no of pages showing in the left and right side of the current page in the anchors
$j = 1;
for($i=$page_showing; $i>1; $i--){
$fpreviousPage = $i-1;
$page = ceil($fpreviousPage*$recpage)-$recpage;
$anch = "<a href='javascript:pagination($page);'>$fpreviousPage | </a>".$anch;
if($j == $norepeat) break;
$j++;
}
$anc .= $anch;
$anc .= $page_showing ."| ";
$j = 1;
for($i=$page_showing; $i<$total_page; $i++){
$fnextPage = $i+1;
$page = ceil($fnextPage*$recpage)-$recpage;
$anc .= "<a href='javascript:pagination($page);'>$fnextPage | </a>";
if($j==$norepeat) break;
$j++;
}
############################################################
if($next >= $numrows){
$anc .= "Next | Last ";
}else{
$anc .= "<a href='javascript:pagination($next);'>Next | </a>";
$anc .= "<a href='javascript:pagination($last);'>Last</a>";
}
$this->anchors = $anc;

$this->total = "<svaluestrong>Page : $page_showing <i> Of </i> $total_page . Total Records Found: $numrows</svaluestrong>";
}
}
?>


Demo Page:


<?php

include('pagination_class.php');
mysql_connect('localhost', 'user', 'pass') or die(mysql_error());
mysql_select_db('std_db');


/*
-- Table structure for table `students`

CREATE TABLE `students` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
);

INSERT INTO `students` VALUES (1, 'Reneesh');
INSERT INTO `students` VALUES (2, 'Aniesh');
INSERT INTO `students` VALUES (3, 'Babu');
INSERT INTO `students` VALUES (4, 'Antony');
INSERT INTO `students` VALUES (5, 'Praveesh');
INSERT INTO `students` VALUES (6, 'Dixon');
INSERT INTO `students` VALUES (7, 'Sanju');
INSERT INTO `students` VALUES (8, 'Neeraj');
INSERT INTO `students` VALUES (9, 'Siju');
INSERT INTO `students` VALUES (10, 'Noble');
INSERT INTO `students` VALUES (11, 'Bibin');
INSERT INTO `students` VALUES (12, 'Febin');
INSERT INTO `students` VALUES (13, 'Binu');
INSERT INTO `students` VALUES (14, 'Charles');
INSERT INTO `students` VALUES (15, 'jaggu');
INSERT INTO `students` VALUES (16, 'mani');
INSERT INTO `students` VALUES (17, 'milu');
INSERT INTO `students` VALUES (18, 'aravind');
INSERT INTO `students` VALUES (19, 'jay');
INSERT INTO `students` VALUES (20, 'hari');
*/
?>

<script language="JavaScript">
function pagination(page)
{
window.location = "testpage.php?search_text="+document.form1.search_text.value+"&starting="+page;
}
</script>
<?
$qry = "SELECT * FROM students";

if($_REQUEST['search_text']!=""){
$searchText = $_REQUEST['search_text'];
$qry .=" where name like '$searchText%'";
}

//for pagination
if(isset($_GET['starting'])&& !isset($_REQUEST['submit'])){
$starting=$_GET['starting'];
}else{
$starting=0;
}
$recpage = 2;//number of records per page

$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;


?><form name="form1" action="testpage.php" method="POST">

<table border="1" width="40%">
<tr>
<TD colspan="2">
Search <input type="text" name="search_text" value="<? echo $searchText;?>">
<input type="submit" value="Search">
</TD>
</tr>
<tr><TD>Sl no</TD><TD>Name</TD></tr>
<?if(mysql_num_rows($result)!=0){
$counter = $starting + 1;
while($data = mysql_fetch_array($result)) {?>
<tr>
<TD><? echo $counter; ?></TD>
<TD><? echo $data['name']; ?></TD>
</tr><?
$counter ++;
} ?>


<tr><TD align="center" colspan="2"><? echo $obj->anchors; ?></TD></tr>
<tr><TD align="center" colspan="2"><? echo $obj->total; ?></TD></tr>
<?}else{
echo "No Data Found";
}?>
</TD></tr></table></form>

Read Me:

Developed by Reneesh T.K
reneeshtk@gmail.com

You can use it with out any worries...It is free for you..It will display the out put like:

First | Previous | 3 | 4 | 5 | 6 | 7| 8 | 9 | 10 | Next | Last
Page : 7 Of 10 . Total Records Found: 20

Just pass the query ,records per page and starting from the page you want to display the pagination.

Advantage: It is connected to search process in the example and you may extend this feature as you like..It can also use in ajax by putting the contents of the javascript function in the ajaxfunction used for ajax.

Or You can Download it from PhpClasses.org

For Zip http://www.phpclasses.org/browse/package/4318/download/zip.html

or

For Tar http://www.phpclasses.org/browse/package/4318/download/targz.html

| 0 comments ]

#******************************************************************************
# function to round a number into two
#******************************************************************************


function roundToTwo($number)
{
return round($number,2);
return round ((
(floatval($number) * (0 + $number/ 100))*100))/100 ;
}

#******************************************************************************

| 0 comments ]

#******************************************************************************
# function to calculate difference between two dates
#******************************************************************************

function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
return $end_date - $start_date;
}

#******************************************************************************

| 0 comments ]

#******************************************************************************
# function to date formate into one to another
#******************************************************************************

function convertDateFormat($datetorev,$currentformat="ymd",$outputformat="dmy",$seperateby="/")
{
//This function is is not completed. the work remaining is adding more format conversions
if (( $currentformat=="ymd") and ($outputformat=="dmy"))
{
list($year, $month, $day) = split('[/.-]', $datetorev);
return $day.$seperateby.$month.$seperateby.$year;

}
else if (( $currentformat=="ymd") and ($outputformat=="mdy"))
{
list( $year,$month,$day) = split('[/.-]', $datetorev);
return $month.$seperateby.$day.$seperateby.$year;

}
else if (( $currentformat=="dmy") and ($outputformat=="ymd"))
{
list( $day,$month,$year) = split('[/.-]', $datetorev);
return $year.$seperateby.$month.$seperateby.$day;

}
else if (( $currentformat=="dmy") and ($outputformat=="mdy"))
{
list( $day,$month,$year) = split('[/.-]', $datetorev);
return $month.$seperateby.$day.$seperateby.$year;

}
else if (( $currentformat=="mdy") and ($outputformat=="ymd"))
{
list( $month,$day,$year) = split('[/.-]', $datetorev);
return $year.$seperateby.$month.$seperateby.$day;

}
else if (( $currentformat=="mdy") and ($outputformat=="dmy"))
{
list( $month,$day,$year) = split('[/.-]', $datetorev);
return $day.$seperateby.$month.$seperateby.$year;

}
else
{
return "Not valid";
}


}

#******************************************************************************

| 0 comments ]

#******************************************************************************
# function to send an email
#******************************************************************************


function send_mail($to, $subject, $message){

if(!isset($to) or !$to or $to == ''){ }else{

$tos = FALSE;
$to = str_replace(' ', '', $to);
if(eregi(',', '')){
$tos = explode(',', $to);
}

$from = 'YouName' . $_SERVER['SERVER_NAME'];

$headers = '';
$headers .= "From: $from\n";
$headers .= "Reply-to: $from\n";
$headers .= "Return-Path: $from\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain;\n";
$headers .= "Date: " . date('r', time()) . "\n";

if($tos){
foreach($tos as $my_to){
@mail($my_to,$subject,$message,$headers);
}
}else{ @mail($to,$subject,$message,$headers); }

}
}

#******************************************************************************

| 0 comments ]

#******************************************************************************
# function to create random keys for email validation
#******************************************************************************

function randomkeys($length)
{
$pattern = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
for($i=0;$i<$length;$i++)
{
$key .= $pattern{rand(0,33)};
}
return $key;
}


#******************************************************************************

| 0 comments ]

#******************************************************************************
# function for convert an image into a thumb and displaying it
#******************************************************************************

function create_thumb($filename,$neww,$newh){
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($filename);
$newwidth = $neww;
$newheight = $newh;
$img = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
imagecopyresampled($img, $source, 0, 0, 0, 0, $newheight, $newheight, $width, $height);
imagejpeg($img);
}

#******************************************************************************

| 0 comments ]

#******************************************************************************
# function to upload a file
#******************************************************************************

function fileupload($fname,$previous){
$filepath='../public';
if(!empty($_FILES[$fname]['name'])){
$imgname = $_FILES[$fname]['name'];
$ext = explode(".",microtime());
$imgname=$ext[1].$imgname;
$imgname=str_replace(' ','',$imgname);
move_uploaded_file($_FILES[$fname]['tmp_name'],"$filepath/$imgname") or die("Image Uploading failed");
}
else {
if(isset($previous)) $imgname=$previous;
else $imgname="N";
}
return $imgname;
}


#******************************************************************************

| 0 comments ]

#******************************************************************************
#function to resize an image
#******************************************************************************

function imageResize($w,$h) {
$tw=500;
$th=850;
$x=$w;
$y=$h;
if($w>$tw && $h>$th){
$x=$tw;
$y=$h*$tw/$w;
}
else
{
if($w>$tw && $h<=$th){ $x=$tw; $y=$h-($w-$tw)/$w*$h; } else if($h>$th && $w<=$tw){
$x=$w-($h-$th)/$h*$w;
$y=$th;
}
}
$width = round($x);
$height = round($y);
return "width=\"$width\" height=\"$height\"";
}


#************************************************************************

| 0 comments ]

#******************************************************************************
#function to checking the password's pattern and its length
#******************************************************************************
function checkPasswordAndStrength($password) {

$strength = 0;
$patterns = array(
'#[a-z]#',
'#[A-Z]#',
'#[0-9]#',
);

foreach($patterns as $pattern) {
if(preg_match($pattern, $password, $matches)) {
$strength++;
}
}

if(strlen($password) >= 8) {
$strength++;
}

return $strength;

}

#************************************************************************