To Upload DataBase:
$filename=$_FILES['imgfile']['name'];
$img="C:\\PHP\\uploadtemp\\".$_FILES['imgfile']['name'];
#
$fh = fopen($_FILES['imgfile']['tmp_name'], "rb");
#
$imgdata = addslashes(fread($fh, filesize($_FILES['imgfile']['tmp_name'])));
#
fclose($fh);
$imgdata store to database as variable
Retrive Image Form Database:
$UserId=$_REQUEST['get'];
//$UserId=1;
$dbconn = mysql_connect('localhost','root','admin') or exit("SERVER Unavailable");
$db=mysql_select_db('test',$dbconn) or exit("DB Unavailable");
$query = "SELECT Image FROM UserLogin where UserId=$UserId";
$result = mysql_query($query, $dbconn) or die('Check Sql Statement');
$result_data = mysql_fetch_array($result, MYSQL_ASSOC);
$img=$result_data['Image'];
if (!empty($img))
{
header("Content-Type: image/jpeg");
$img=$result_data['Image'];
echo $img;
}
else
{
$imgfile="../Image/NotFound.jpg";
$img=imagecreatefromjpeg($imgfile);
header("Content-Type: image/jpeg");
imagejpeg($img);
}
exit();
?>
Thursday, August 14, 2008
Saturday, August 2, 2008
Javascript for Work WIth Ajax
// JavaScript Document
//var xmlHttp = //createXmlHttpRequestObject();
//IF Page Submit/Postback
TimerId=0;
TimerId=setTimeout('GetPastDtl(document.getElementById("CompList").value)',1000);
function createXmlHttpRequestObject()
{
try
{
// try to create XMLHttpRequest object
//xmlHttp = new //XMLHttpRequest();
}
catch(e)
{
var //XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
//for (var i=0; i";
document.getElementById('DeptList').options.add(k);
for (var i=0; i
document.getElementById('EmpList').options.add(l);
for (var m=0; m0)
{
i=document.getElementById('EditedRowNo').value;
GetEditMode('divEd'+i,'divRd'+i,'divNameEd'+i,'divNameRd'+i,'divMailEd'+i,'divMailRd'+i,ENameDtlArray.length);
}
}
function GetEmpDetail()
{
CompId=document.getElementById('CompList').value;
DeptId=document.getElementById('DeptList').value;
EmpId=document.getElementById('EmpList').value;
PageSize=document.getElementById('hdnPageSize').value;
Offset=document.getElementById('hdnoffset').value;
CurrnentPg=document.getElementById('hdnCurrPg').value;
TotalPg=document.getElementById('hdnTotalRow').value;
if (xmlHttp)
{
try
{
if((xmlHttp.readyState==0)||(xmlHttp.readyState==4))
{
var params = "CompId=" + CompId+"&DeptId="+DeptId+"&EmpId="+EmpId+"&PageSize="+PageSize+"&Offset="+Offset;
//xmlHttp.open("GET", "Xml/EmpToDetail.php?" + params, true);
//xmlHttp.onreadystatechange = EmpDtlRequestStateChange;
//xmlHttp.send(null);
}
else
{
setTimeout('GetEmpDetail()',1000);
}
}
catch (e)
{
alert("Can't connect to server:\n" + e.toString());
}
}
}
function CreateTd(id,style,className,innerHTML)
{
Td=document.createElement("td","");
Td.setAttribute("id",id);
Td.setAttribute("style",style);
Td.className=className;
Td.innerHTML=innerHTML;
return Td;
}
function CreateTextBox(AttributeArray,ValueArray,Value)
{
inputName=document.createElement("input","");
for(i=0;i<=AttributeArray.length-1;i++) { inputName.setAttribute(AttributeArray[i],ValueArray[i]); } inputName.value=Value; return inputName; } function GridTable() { document.getElementById("EmpDetail").innerHTML=""; div=document.getElementById("EmpDetail"); //Generate Table Table=document.createElement("table",""); Table.setAttribute("style","width:100%"); Table.setAttribute("cellpadding","0"); Table.setAttribute("cellspacing","0"); Table.setAttribute("border","1"); //Generate Row Tr=document.createElement("tr",""); //Generate Column1 Td1=CreateTd('','width:40%','TdDataHeading','Name'); Tr.appendChild(Td1); //Generate Column2 Td2=CreateTd('','width:40%','TdDataHeading','Email'); Tr.appendChild(Td2); //Generate Coloumn3 Td3=CreateTd('','width:20%','TdDataHeading','Manage'); Tr.appendChild(Td3); Table.appendChild(Tr); ENameDtlArray = xmlRoot.getElementsByTagName("Ename"); EmailDtlArray = xmlRoot.getElementsByTagName("Email"); EContactIdArray=xmlRoot.getElementsByTagName("EContactId"); for (var i=0; i0)&&(i==document.getElementById('EditedRowNo').value))
{
UpdateErrMsg=UpdateArray.item(0).firstChild.data;
divErr.innerHTML=UpdateErrMsg;
}
Td1.appendChild(divErr);
Tr.appendChild(Td1);
//Generate Column2
Td2=CreateTd('','width:40%','TdData','');
divMailRd=document.createElement("div","");
divMailRd.setAttribute('id','divMailRd'+i);
divMailRd.innerHTML=mail;
Td2.appendChild(divMailRd);
divMailEd=document.createElement("div","");
divMailEd.setAttribute('id','divMailEd'+i);
divMailEd.setAttribute('style','display:none');
//Edit Text
inputMail=CreateTextBox(['type','name','id'],['text','textmail'+i,'textmail'+i],mail);
divMailEd.appendChild(inputMail)
//--
Td2.appendChild(divMailEd);
Tr.appendChild(Td2);
//Generate Column3
Td3=CreateTd('','width:20%','TdData','');
//Div for Readmode Link
DivRd=document.createElement("div","");
DivRd.setAttribute("id","divRd"+i);
EditLink=document.createElement("a","");
EditLink.setAttribute("href","Javascript");
EditLink.setAttribute("onClick",
"return GetEditMode('divEd"+i+"','divRd"+i+"','divNameEd"+i+"','divNameRd"+i+"','divMailEd"+i+"','divMailRd"+i+"',ENameDtlArray.length);");
EditLink.innerHTML="Edit";
DivRd.appendChild(EditLink);
Td3.appendChild(DivRd);
//-------
//Div for Editmode Link
DivEd=document.createElement("div","");
DivEd.setAttribute("id","divEd"+i);
DivEd.setAttribute("style","display:none");
UpdateLink=document.createElement("a","");
UpdateLink.setAttribute("href","Javascript");
UpdateLink.setAttribute("onClick","return GetDataUpdate('hdnConId"+i+"','text"+i+"','divNameRd"+i+"','textmail"+i+"','divMailRd"+i+"','divErr"+i+"');");
UpdateLink.innerHTML="Update |";
DivEd.appendChild(UpdateLink);
CancelLink=document.createElement("a","");
CancelLink.setAttribute("href","Javascript");
CancelLink.setAttribute("onClick",
"return GetReadMode('divEd"+i+"','divRd"+i+"','divNameEd"+i+"','divNameRd"+i+"','divMailEd"+i+"','divMailRd"+i+"','divErr"+i+"');");
CancelLink.innerHTML="Cancel";
DivEd.appendChild(CancelLink);
Td3.appendChild(DivEd);
//-------
Tr.appendChild(Td3);
Table.appendChild(Tr);
}
return div.appendChild(Table);
}
function CheckName(Name)
{
alert(Name);
return false;
}
function GetEditMode(divEdit,divRead,divNameEd,divNameRd,divMailEd,divMailRd,Trow)
{
document.getElementById('EditedRowNo').value=divEdit.split('divEd')[1];
var i;
i=0;
for(i=0;i1))
{
document.getElementById('hdnCurrPg').value=parseInt(currPg)-1;
document.getElementById('hdnoffset').value=parseInt(document.getElementById('hdnoffset').value)-parseInt(PageSize);
GetEmpDetail();
}
return false;
}
function DropChange()
{
document.getElementById('hdnCurrPg').value=1;
document.getElementById('hdnoffset').value=0;
document.getElementById('hdnTotalRow').value='';
document.getElementById('hdnTotalPage').value='';
GetEmpDetail();
}
//var xmlHttp = //createXmlHttpRequestObject();
//IF Page Submit/Postback
TimerId=0;
TimerId=setTimeout('GetPastDtl(document.getElementById("CompList").value)',1000);
function createXmlHttpRequestObject()
{
try
{
// try to create XMLHttpRequest object
//xmlHttp = new //XMLHttpRequest();
}
catch(e)
{
var //XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
//for (var i=0; i";
document.getElementById('DeptList').options.add(k);
for (var i=0; i
document.getElementById('EmpList').options.add(l);
for (var m=0; m
{
i=document.getElementById('EditedRowNo').value;
GetEditMode('divEd'+i,'divRd'+i,'divNameEd'+i,'divNameRd'+i,'divMailEd'+i,'divMailRd'+i,ENameDtlArray.length);
}
}
function GetEmpDetail()
{
CompId=document.getElementById('CompList').value;
DeptId=document.getElementById('DeptList').value;
EmpId=document.getElementById('EmpList').value;
PageSize=document.getElementById('hdnPageSize').value;
Offset=document.getElementById('hdnoffset').value;
CurrnentPg=document.getElementById('hdnCurrPg').value;
TotalPg=document.getElementById('hdnTotalRow').value;
if (xmlHttp)
{
try
{
if((xmlHttp.readyState==0)||(xmlHttp.readyState==4))
{
var params = "CompId=" + CompId+"&DeptId="+DeptId+"&EmpId="+EmpId+"&PageSize="+PageSize+"&Offset="+Offset;
//xmlHttp.open("GET", "Xml/EmpToDetail.php?" + params, true);
//xmlHttp.onreadystatechange = EmpDtlRequestStateChange;
//xmlHttp.send(null);
}
else
{
setTimeout('GetEmpDetail()',1000);
}
}
catch (e)
{
alert("Can't connect to server:\n" + e.toString());
}
}
}
function CreateTd(id,style,className,innerHTML)
{
Td=document.createElement("td","");
Td.setAttribute("id",id);
Td.setAttribute("style",style);
Td.className=className;
Td.innerHTML=innerHTML;
return Td;
}
function CreateTextBox(AttributeArray,ValueArray,Value)
{
inputName=document.createElement("input","");
for(i=0;i<=AttributeArray.length-1;i++) { inputName.setAttribute(AttributeArray[i],ValueArray[i]); } inputName.value=Value; return inputName; } function GridTable() { document.getElementById("EmpDetail").innerHTML=""; div=document.getElementById("EmpDetail"); //Generate Table Table=document.createElement("table",""); Table.setAttribute("style","width:100%"); Table.setAttribute("cellpadding","0"); Table.setAttribute("cellspacing","0"); Table.setAttribute("border","1"); //Generate Row Tr=document.createElement("tr",""); //Generate Column1 Td1=CreateTd('','width:40%','TdDataHeading','Name'); Tr.appendChild(Td1); //Generate Column2 Td2=CreateTd('','width:40%','TdDataHeading','Email'); Tr.appendChild(Td2); //Generate Coloumn3 Td3=CreateTd('','width:20%','TdDataHeading','Manage'); Tr.appendChild(Td3); Table.appendChild(Tr); ENameDtlArray = xmlRoot.getElementsByTagName("Ename"); EmailDtlArray = xmlRoot.getElementsByTagName("Email"); EContactIdArray=xmlRoot.getElementsByTagName("EContactId"); for (var i=0; i
{
UpdateErrMsg=UpdateArray.item(0).firstChild.data;
divErr.innerHTML=UpdateErrMsg;
}
Td1.appendChild(divErr);
Tr.appendChild(Td1);
//Generate Column2
Td2=CreateTd('','width:40%','TdData','');
divMailRd=document.createElement("div","");
divMailRd.setAttribute('id','divMailRd'+i);
divMailRd.innerHTML=mail;
Td2.appendChild(divMailRd);
divMailEd=document.createElement("div","");
divMailEd.setAttribute('id','divMailEd'+i);
divMailEd.setAttribute('style','display:none');
//Edit Text
inputMail=CreateTextBox(['type','name','id'],['text','textmail'+i,'textmail'+i],mail);
divMailEd.appendChild(inputMail)
//--
Td2.appendChild(divMailEd);
Tr.appendChild(Td2);
//Generate Column3
Td3=CreateTd('','width:20%','TdData','');
//Div for Readmode Link
DivRd=document.createElement("div","");
DivRd.setAttribute("id","divRd"+i);
EditLink=document.createElement("a","");
EditLink.setAttribute("href","Javascript");
EditLink.setAttribute("onClick",
"return GetEditMode('divEd"+i+"','divRd"+i+"','divNameEd"+i+"','divNameRd"+i+"','divMailEd"+i+"','divMailRd"+i+"',ENameDtlArray.length);");
EditLink.innerHTML="Edit";
DivRd.appendChild(EditLink);
Td3.appendChild(DivRd);
//-------
//Div for Editmode Link
DivEd=document.createElement("div","");
DivEd.setAttribute("id","divEd"+i);
DivEd.setAttribute("style","display:none");
UpdateLink=document.createElement("a","");
UpdateLink.setAttribute("href","Javascript");
UpdateLink.setAttribute("onClick","return GetDataUpdate('hdnConId"+i+"','text"+i+"','divNameRd"+i+"','textmail"+i+"','divMailRd"+i+"','divErr"+i+"');");
UpdateLink.innerHTML="Update |";
DivEd.appendChild(UpdateLink);
CancelLink=document.createElement("a","");
CancelLink.setAttribute("href","Javascript");
CancelLink.setAttribute("onClick",
"return GetReadMode('divEd"+i+"','divRd"+i+"','divNameEd"+i+"','divNameRd"+i+"','divMailEd"+i+"','divMailRd"+i+"','divErr"+i+"');");
CancelLink.innerHTML="Cancel";
DivEd.appendChild(CancelLink);
Td3.appendChild(DivEd);
//-------
Tr.appendChild(Td3);
Table.appendChild(Tr);
}
return div.appendChild(Table);
}
function CheckName(Name)
{
alert(Name);
return false;
}
function GetEditMode(divEdit,divRead,divNameEd,divNameRd,divMailEd,divMailRd,Trow)
{
document.getElementById('EditedRowNo').value=divEdit.split('divEd')[1];
var i;
i=0;
for(i=0;i
{
document.getElementById('hdnCurrPg').value=parseInt(currPg)-1;
document.getElementById('hdnoffset').value=parseInt(document.getElementById('hdnoffset').value)-parseInt(PageSize);
GetEmpDetail();
}
return false;
}
function DropChange()
{
document.getElementById('hdnCurrPg').value=1;
document.getElementById('hdnoffset').value=0;
document.getElementById('hdnTotalRow').value='';
document.getElementById('hdnTotalPage').value='';
GetEmpDetail();
}
Subscribe to:
Posts (Atom)