September 18, 2008

PHP send mail

Here is the function which you can send Email to any account by your gmail account
==============================
function sendmail(){
require_once("class/class.phpgmailer.php");
$mail = new PHPGMailer();
$mail->Username = "your name";
$mail->Password = "your gmail's password";
$mail->From = "your gmail's account(full)";
$mail->FromName = 'your display name';
$mail->Subject = 'your subject';
$mail->AddAddress("destination address");
$mail->Body =trim("your content");
$mail->Send();
return "mail was sent";
}

------------------------------------
you must include 3 classes in this file below:
http://www.esnips.com/doc/d7cbc4df-104a-4db6-9e4a-e46939326160/PHP-send-mail

September 09, 2008

Ajax for getting RSS from other sites

Here are the functions which you can request the RSS Hot News from Yahoo, Google, Hotmail, Craigslist, BBC and CNN and display them in your page.
======================================
--------------------First step------------------------

//Here are the function that I use to display RSS.
var xmlHttp
function showRSS(str) {
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request")
return }
var url="getrss.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() {
if (xmlHttp.readyState==1){
document.getElementById("rssOutput").innerHTML="Loading..."
}else if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("rssOutput").innerHTML=xmlHttp.responseText
}}
function GetXmlHttpObject(){
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }
return xmlHttp;}

--------------------Second step------------------------

//here is the php script which I use to get the RSS.
$q=$_GET["q"];//find out which feed was selected
if($q=="2") {
$xml=("http://news.google.com/news?ned=us&topic=h&output=rss");
}elseif($q=="3") {
$xml=("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");
}elseif($q=="1"){
$xml=("http://rss.news.yahoo.com/rss/topstories");
}elseif($q=="4"){
$xml=("http://webns.net/mvcb/");
//$xml=("http://newyork.craigslist.org/ccc/index.rss");
}elseif($q=="5_1"){
$xml=("http://rss.cnn.com/rss/cnn_topstories.rss");
}elseif($q=="5_2"){
$xml=("http://rss.cnn.com/rss/cnn_latest.rss");
}elseif($q=="6"){
$xml=("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml");}

$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);//get elements from ""
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
if($q!="4"){
$channel_title = $channel->getElementsByTagName('title')->item(0)-> childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')->item(0)-> childNodes->item(0)->nodeValue;
}
$channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes-> item(0)->nodeValue;//output elements from ""
echo("<p><a href= $channel_link>$channel_title</a>");
echo("
");
echo($channel_desc . "

");
//get and output "" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=9; $i++) {
$item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue;
$item_link=$x->item($i)->getElementsByTagName('link') ->item(0)-> childNodes->item(0)->nodeValue;
if($q!="4"){
$item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue;
}
echo ("<p><a href=$item_link>$item_title</a>");
echo ("
");
echo ($item_desc . "

");
}

September 08, 2008

Ajax request

Here is the function which you can use to execute the server script without refreshing the page.
======================================

function Ajaxrequest(){
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest(); }
catch (e)
{ // Internet Explorer
try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{ alert("Your browser does not support AJAX!");
return false; } } }
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==1){
document.getElementById('display').innerHTML="Loading...!";
}
if(xmlHttp.readyState==4)
{
document.getElementById('display').innerHTML=xmlHttp.responseText;
}
}
//alert(page);
xmlHttp.open("GET","URL",true);
xmlHttp.send(null);
}

September 07, 2008

php paging

Here is the function which you can paging your data to next or previous
======================================

//$page is refer to the page which you will link to.
//$startnum is refer to the startnumber in limit
//$numrow is refer to the number of record in limit
//$maxrow is the count number of your data
function paging($page,$startnum,$numrow,$maxrow){
if($startnum<=0){
$btnprevious="Previous";
}else{
$btnprevious="<a href=$page?startnum=$startnum-$numrow>Previous</a>";
}
if($startnum+$numrow < $maxrow){
$btnnext="<a href=$page?$startnum+$numrow>Next</a>";
}else{
$btnnext="Next";
}
return $btnprevious."  ".$btnnext;
}

September 04, 2008

php file system

Here is the function which is used to delete a folder and all sub folders and files in it.
=======================================

function removeallfile($dirname){
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
unlink($dirname."/".$file);
}
}
closedir($dir_handle);
return true;
}


Here is the function which is used for copy all files from 1 folder to another folder
=======================================

function copydir($dirname1,$dirname2)
{
if (is_dir($dirname1))
$dir_handle = opendir($dirname1);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname1."/".$file))
$tempfile=fopen($dirname2."/".$file,"w+");
copy($dirname1."/".$file,$dirname2."/".$file);
//unlink($dirname1."/".$file);
}
}
closedir($dir_handle);
return true;
}


Here are the files which contain upload file function and you can upload your file by using these files.
=======================================
1./ http://www.esnips.com/doc/1bc71467-47d8-4085-9afd-d2073c725513/upload
2./ http://www.esnips.com/doc/33d8a913-5bc7-498b-9c26-74f59af4dc07/upload-file