Tuesday 17 November 2009

Smarty variable in javascript

{literal}
!---script
$(window).load(function() { var sample=’/sample.php?v={/literal}{$smarty_variable}{literal}’; });
/script---
{/literal}

Tuesday 8 September 2009

Code to Fetch Youtube Video's Image (JS)

///
//// functionjo getScreen( url, size )
///{
///alert(url);
//alert(size);
// if(url === null){ return ""; }

// size = (size === null) ? "big" : size;
/ var vid;
// var results;

// results = url.match("[\\?&]v=([^&#]*)");

// vid = ( results === null ) ? url : results[1];

/// if(size == "small"){
/// alert("http://img.youtube.com/vi/"+vid+"/2.jpg");
// return "http://img.youtube.com/vi/"+vid+"/2.jpg";
/// }else {
/// alert("http://img.youtube.com/vi/"+vid+"/0.jpg");
/// return "http://img.youtube.com/vi/"+vid+"/0.jpg";
/// }
// }
//



///// function call /////

////onload="getScreen('http://www.youtube.com/watch?v=-4ce_C2Cako', 'small');"

Tuesday 1 September 2009

video conversion codes - through FFMPEG

// system("/usr/bin/ffmpeg -i 1214564751.wmv -r 25 -acodec mp3 -ar 22050 -s 320x240 video.flv");

//system("ffmpeg -i 1214564751.wmv -ar 22050 1111.flv");

//system("/usr/bin/ffmpeg -i videos/12170871531204448905_64.wmv -r 25 -acodec mp3 -ar 22050 -s 320x240 -y videos/testflv.flv");

/* image converter

system("/usr/local/bin/ffmpeg -i lmtttt.flv -vcodec png -vframes 1 -an -f rawvideo -s 320×240 lmmmm.jpg");

*/

// system("/usr/local/bin/ffmpeg -i mobile.avi -r 25 -acodec mp3 -ar 22050 -s 320x240 avijo.flv");

system("/usr/local/bin/ffmpeg -i mobile.avi -ar 22050 avijo1111.flv");

system("/usr/local/bin/ffmpeg -i Penquen.mpg -ar 22050 mpgjo.flv");

system("/usr/local/bin/ffmpeg -i baby_dance.wmv -ar 22050 wmvjo.flv");

//system("/usr/bin/ffmpeg -i clock.avi -r 25 -acodec mp3 -ar 22050 -s 320x240 jo1.flv");

//exec("/usr/bin/ffmpeg -i clock.avi -r 25 -acodec mp3 -ar 22050 -s 320x240 jo2.flv");

//exec("/usr/bin/ffmpeg -i clock.avi -r 25 -acodec mp3 -ar 22050 -s 320x240 jo3.flv");

Monday 3 August 2009

Inner Select

//// Single2:

Monday 27 July 2009

BYTES TO OTHER FORMATS

function HumanSize($Bytes)
{
$Type=array("", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta");
$Index=0;
while($Bytes>=1024)
{
$Bytes/=1024;
$Index++;
}
return("".$Bytes." ".$Type[$Index]."bytes");
}

echo HumanSize(33535356576765656766656445456);
?>

To get the alphabets in Loop function

for ($i = 65; $i <= 90; $i++)
{

echo $drive = chr($i);

}

OUTPUT:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

To get the disk space of your system using php

for ($i = 67; $i <= 90; $i++)
{
$drive = chr($i);
if (
is_dir($drive.':'))
{
$freespace = disk_free_space($drive.':');
$total_space = disk_total_space($drive.':');
$percentage_free = $freespace ? round($freespace / $total_space, 2) * 100 : 0;
echo
$drive.': '.to_readble_size($freespace).' / '.to_readble_size($total_space).' ['.$percentage_free.'%]
'
;
}
}

function
to_readble_size($size)
{
switch (
true)
{
case (
$size > 1000000000000):
$size /= 1000000000000;
$suffix = 'TB';
break;
case (
$size > 1000000000):
$size /= 1000000000;
$suffix = 'GB';
break;
case (
$size > 1000000):
$size /= 1000000;
$suffix = 'MB';
break;
case (
$size > 1000):
$size /= 1000;
$suffix = 'KB';
break;
default:
$suffix = 'B';
}
return
round($size, 2).$suffix;
}
?>

Thursday 18 June 2009

Apache Directives

Wednesday 17 June 2009

htaccess sample file

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.9lessons.blogspot.com
RewriteRule (.*) http://9lessons.blogspot.com/$1 [R=301,L]

RewriteEngine on
RewriteRule ^(.*)\$ $1.php


RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\view$ allbox.php?ur=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\groups$ allgroups.php?ur=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\following$ allfollowing.php?ur=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\followers$ allfollowers.php?ur=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\trash$ inbox.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\tras$ newbox.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\group$ groupbox.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/\inbox$ mybox.php?id=$1


RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)\/bookmarks$ pubbook.php?ur=$1

=========================================================
Custom Error Pages

The first use of the .htaccess file which I will cover is custom error pages. These will allow you to have your own, personal error pages (for example when a file is not found) instead of using your host's error pages or having no page. This will make your site seem much more professional in the unlikely event of an error. It will also allow you to create scripts to notify you if there is an error (for example I use a PHP script on Free Webmaster Help to automatically e-mail me when a page is not found).

You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file:

ErrorDocument errornumber /file.html

For example if I had the file notfound.html in the root direct
ory of my site and I wanted to use it for a 404 error I would use:

ErrorDocument 404 /notfound.html

If the file is not in the root directory of your site, you just need to put the path to it:

ErrorDocument 500 /errorpages/500.html

These are some of the most common errors:

401 - Authorization Required
400 - Bad request
403 - Forbidden
500 - Internal Server Error
404 - Wrong page

Then, all you need to do is to create a file to display when the error happens and upload it and the .htaccess file.



Deny/Allow Certian IP Addresses
You can block an IP address by using:

deny from 000.000.000.000


You can allow an IP address by using:

allow from 000.000.000.000



If you want to deny everyone from accessing a directory, you can use:

deny from all

======================================================

Alternative Index Files

You may not always want to use index.htm or index.html as your index file for a directory, for example if you are using PHP files in your site, you may want index.php to be the index file for a directory. You are not limited to 'index' files though. Using .htaccess you can set foofoo.blah to be your index file if you want to!

Alternate index files are entered in a list. The server will work from left to right, checking to see if each file exists, if none of them exisit it will display a directory listing (unless, of course, you have turned this off).

DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm

Redirection

One of the most useful functions of the .htaccess file is to redirect requests to different files, either on the same server, or on a completely different web site. It can be extremely useful if you change the name of one of your files but allow users to still find it. Another use (which I find very useful) is to redirect to a longer URL, for example in my newsletters I can use a very short URL for my affiliate links. The following can be done to redirect a specific file:

Redirect /location/from/root/file.ext http://www.othersite.com/new/file/location.xyz

In this above example, a file in the root directory called oldfile.html would be entered as:

/oldfile.html

and a file in the old subdirectory would be entered as:

/old/oldfile.html

You can also redirect whole directoires of your site using the .htaccess file, for example if you had a directory called olddirectory on your site and you had set up the same files on a new site at: http://www.newsite.com/newdirectory/ you could redirect all the files in that directory without having to specify each one:

Redirect /olddirectory http://www.newsite.com/newdirectory

Then, any request to your site below /olddirectory will bee redirected to the new site, with the
extra information in the URL added on, for example if someone typed in:

http://www.youroldsite.com/olddirecotry/oldfiles/images/image.gif

They would be redirected to:

http://www.newsite.com/newdirectory/oldfiles/images/image.gif

This can prove to be extremely powerful if used correctly.
=======================================================




Bar chart in php - Chart in php

$v)
if (abs($v) > $max)
$max = abs($v);

if ($max != 0)
$kf = $height / $max;
else
$kf = 0;

if ($width != '')
$width = "width: {$width}px; ";

$out = "";
foreach($values as $k=>$v)
{
$bar_h = abs(round($v*$kf));
$out .= "";
$out .= "{$v}";
}
$out .= '';


$out .= "";

foreach($values as $k=>$v)
$out .= "{$k}";

$out .= "";
return $out;
}

###########################################################################
function ae_bar_css(&$values, $height=100, $css_prefix='')
{
$max = -1;

foreach($values as $k=>$v)
if (abs($v) > $max)
$max = abs($v);

if ($max != 0)
$kf = $height / $max;
else
$kf = 0;

$out = "";
foreach($values as $k=>$v)
{
$bar_h = abs(round($v*$kf));
$out .= "{$v}";
}
$out .= '';


$out .= "";

foreach($values as $k=>$v)
$out .= "{$k}";

$out .= "";
return $out;
}

#####################################################################################

?>

/////ehter the html title here/////



';
echo ae_bar_css($sinus, 100);
echo '';
?>




And this is the ouput:

Tuesday 16 June 2009

Href in Smarty

there is no separate prompt for the HREF option in smarty template

For Example:


A b O u T * m E

I am a web developer. Want to share some tips from you people

Happy coding
Jo

Thursday 28 May 2009

Merging String with the image in php


header("Content-type: image/jpeg");
$string = "jothirajafgjhvdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsgdsdsg
sdgdsgdsgdsgdsg";
$im = imagecreatefromjpeg("butterfly.jpg");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 40.5 * strlen($string)) / 100;
imagestring($im, 3, $px, 380, $string, $orange);
imagejpeg($im);
$jothirajan_a= "IMAGE_".date('d').time().".jpg";
imagejpeg ($im,"image/".$jothirajan_a."");
imagedestroy($im);
?>

Merging images in php

$imgStop = imagecreatefromjpeg("AAKX001003.jpg"); /* Attempt to open */


$imgThumb = imagecreatefromjpeg("AXR001600.jpg");


imagecopy($imgThumb,$imgStop,0,450,0,0,480,50);


header("Content-type: image/jpeg");
imagejpeg($imgThumb);


$jothirajan_a= "IMAGE_".date('d').time().".jpg";
imagejpeg ($imgThumb,"image/".$jothirajan_a."");
imagedestroy($imgThumb);

?>

Image to image merging in php

>>> Create folder called image/

This is my code
$imgStop = imagecreatefromjpeg("AAKX001003.jpg"); /* Attempt to open */

$imgThumb = imagecreatefromjpeg("AXR001600.jpg");

imagecopy($imgThumb,$imgStop,0,450,0,0,480,50);

header("Content-type: image/jpeg");

imagejpeg($imgThumb);

$jothirajan_a= "IMAGE_".date('d').time().".jpg";

imagejpeg ($imgThumb,"image/".$jothirajan_a."");

imagedestroy($imgThumb);

?>

Thursday 16 April 2009

Encrpt and Decrypt the Password in PHP


FUNCTION
ENCRYPT_DECRYPT1($Str_Message) {

$Len_Str_Message=STRLEN($Str_Message);
$Str_Encrypted_Message="";
echo
$Str_Encrypted_Message."
"
;
FOR (
$Position = 0;$Position<$Len_Str_Message;$Position++){

$Key_To_Use = (($Len_Str_Message+$Position)+1);
$Key_To_Use = (255+$Key_To_Use) % 255;
$Byte_To_Be_Encrypted = SUBSTR($Str_Message, $Position, 1);
$Ascii_Num_Byte_To_Encrypt = ORD($Byte_To_Be_Encrypted);
$Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use;
$Encrypted_Byte = CHR($Xored_Byte);
$Str_Encrypted_Message .= $Encrypted_Byte;


}
RETURN
$Str_Encrypted_Message;
}

Wednesday 15 April 2009

Close the POPUP and REDIRECT to Parent

" close the popup window and redirect to the parent window

Dreamweaver users click here "

Simple image popup


onClick="window.open('listing_image/{$eat[test].listing_image}','', 'width=,height=,scrollbars=0');
return false;">Click to Enlarge<

Image validation

function checkPhoto(imagePath) {
var pathLength = imagePath.length;
var lastDot = imagePath.lastIndexOf(".");
var fileType = imagePath.substring(lastDot,pathLength);

if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".png") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".PNG")) {
return true;
} else {
alert("We supports .JPG, .PNG, and .GIF image formats. Your file-type is " + fileType + ". If you are having difficulties with this step, please send an e-mail to trevor@trevor.net.");
}
}

Current page URL


function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
You can now get the current page URL using the line:

echo curPageURL();
?>
Sometimes it is needed to get the page name only. The following example shows how to do it:

function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
echo "The current page name is ".curPageName();
?>

Betwee,Difference between dates,Past added records

Some time we have to collect last 7 or 15 days or X days (or month, year or week) data from MySQL table. For example let us find out who are the new members joined in our forum in last week. One shop may be interested in knowing new products added in last one month. What are the books arrived in last one year. Here irrespective of the date values we want the records of last X days from today, or we can say that the records between today and last X days ( month , year or week) are required.

We will use the MySQL function CURDATE() to get the today’s date.

To get the difference in today date and previous day or month we have to use the MySQL function DATE_SUB

DATE_SUB is a MySQL function which takes date expression, the interval and the constant to return the date value for further calculation.

Here are some sample queries on how to get the records as per requirements .

select * from dt_tb where `dt` >= DATE_SUB(CURDATE(), INTERVAL 15 DAY)

The above query will return last 15 days records. Note that this query will return all future dates also. To exclude future dates we have to modify the above command a little by using between query to get records. Here is the modified one.

SELECT * FROM dt_tb WHERE `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 15 DAY ) AND CURDATE( )

Let us try to get records added in last one month

select * from dt_tb where `dt` >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)

Here also future records will be returned so we can take care of that by using BETWEEN commands if required.

select * from dt_tb where `dt` >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)

You can easily make out what the above query will return.

We can collect records between a particular date ranges by using between command and DATE_SUB. Here are some queries to generate records between two date ranges.

select * from dt_tb where `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 3 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )

This query will return records between last three months. This query again we will modify to get the records between three moths and six months.

select * from dt_tb where `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 6 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 3 MONTH )

Now let us change this to get records between 6 month and 12 month.

select * from dt_tb where `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 12 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 6 MONTH )

With this you can understand how the records between a month range or a year range can be collected from a table. Note that the months ranges are calculated starting from current day. So if we are collecting records of last three months and we are in 15th day of 9th month then records of 15th day of 6th month we will get but the records of 14th day of 6th month will be returning on next query that is between 3 months and 6 months.

Now let us try a different requirement. How to get the records of the working days of the week so far ? If today is Thursday then records from Monday to Thursday should be returned. We will discuss this in our next section >>.

Here is the sql code to create and fill the table with records

CREATE TABLE `dt_tb` ( `id` int(2) NOT NULL auto_increment, `dt` datetime NOT NULL default ‘0000-00-00 00:00:00', `dt2` date NOT NULL default ‘0000-00-00', UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;



INSERT INTO `dt_tb` VALUES (1, ‘2007-02-15 00:00:00', ‘2005-01-25');
INSERT INTO `dt_tb` VALUES (2, ‘2007-02-12 23:56:54', ‘2005-06-12');
INSERT INTO `dt_tb` VALUES (3, ‘2005-12-08 13:20:10', ‘2005-06-06');
INSERT INTO `dt_tb` VALUES (5, ‘2005-02-10 00:00:00', ‘2006-01-02');
INSERT INTO `dt_tb` VALUES (6, ‘2006-11-26 00:00:00', ‘2006-12-25');
INSERT INTO `dt_tb` VALUES (7, ‘2006-11-26 00:00:00', ‘2007-02-25');
INSERT INTO `dt_tb` VALUES (8, ‘2007-10-20 00:00:00', ‘2007-10-25');
INSERT INTO `dt_tb` VALUES (9, ‘2007-02-11 00:00:00', ‘2007-01-25');
INSERT INTO `dt_tb` VALUES (10, ‘2007-01-22 00:00:00', ‘2007-01


--- my format ----

/////////////////////////////

$eee=
"select * from
video_contest
where `start_date` >= DATE_SUB(CURDATE(), INTERVAL 1 year)";
$exe_4=mysql_query($eee);
$res_4=mysql_num_rows($exe_4);
echo $res_4;
//////////////////////////////