Friday, May 20, 2011
Thursday, May 19, 2011
Wednesday, May 18, 2011
Client / Server Data Retrieval With JSON
Now that you are well versed with the concepts and syntax of JSON, and you have a working example of how to use JSON for client-side API communication, let's see how we can take advantage of server-side technologies to transfer data between the client and the server.
Until recently, the world of asynchronous communication was ruled by XML. While in production successfully, XML is still an extremely bulky language, increasing data transfer overhead. Perhaps its biggest downfall, however, is that XML is commonly generated by server languages who many times do not have an XML converter, requiring manual conversion. Then, they are delivered to client languages, most notably JavaScript, who also do not have native support for XML. It would make more sense, for code simplicity and maintenance, for everyone to speak the same language.
Until recently, the world of asynchronous communication was ruled by XML. While in production successfully, XML is still an extremely bulky language, increasing data transfer overhead. Perhaps its biggest downfall, however, is that XML is commonly generated by server languages who many times do not have an XML converter, requiring manual conversion. Then, they are delivered to client languages, most notably JavaScript, who also do not have native support for XML. It would make more sense, for code simplicity and maintenance, for everyone to speak the same language.
Monday, May 16, 2011
Sunday, May 15, 2011
upload multiple using php script
<title>Untitled Document</title>
<script language="javascript" >
function addFile()
{
table =document.getElementById("tabFileup");
var count=table.rows.length;
var row=table.insertRow(count-1);
var cell1=row.insertCell(0);
cell1.innerHTML = "<div align='center'>Upload file</div>";
/*var cell2=row.insertCell(1);
var ele=document.createElement("input");
ele.type="file";
ele.name="fileImage[]";
cell2.appendChild(ele);*/
var cell2=row.insertCell(1);
cell2.innerHTML = " <td colspan='2'><input name='fileImage[]' type='file' /><a href='#' onclick='addFile();'>add another</a></td>";
alert(count);
}
</script>
</head>
<body>
<form action="uploadFileAction.php" method="post" enctype="multipart/form-data" name="frmUpload">
<table id="tabFileup" align="center" width="80%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="45%"><div align="center">Server</div></td>
<td width="55%"><input name="txtServer" type="text" /></td>
</tr>
<tr>
<td><div align="center">UserName</div></td>
<td colspan="2"><input name="txtUser" type="text" /></td>
</tr>
<tr>
<td><div align="center">Password</div></td>
<td colspan="2"><input name="txtPass" type="password" /></td>
</tr>
<tr>
<td><div align="center">Upload file</div></td>
<td colspan="2"><input name="fileImage[]" type="file" /><a href="#" onclick="addFile();">add another</a></td>
</tr>
<tr>
<td>
<div align="center">
<input name="btnSubmit" type="submit" value="submit" />
</div></td>
<td colspan="2"><input name="btnReset" type="reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
<script language="javascript" >
function addFile()
{
table =document.getElementById("tabFileup");
var count=table.rows.length;
var row=table.insertRow(count-1);
var cell1=row.insertCell(0);
cell1.innerHTML = "<div align='center'>Upload file</div>";
/*var cell2=row.insertCell(1);
var ele=document.createElement("input");
ele.type="file";
ele.name="fileImage[]";
cell2.appendChild(ele);*/
var cell2=row.insertCell(1);
cell2.innerHTML = " <td colspan='2'><input name='fileImage[]' type='file' /><a href='#' onclick='addFile();'>add another</a></td>";
alert(count);
}
</script>
</head>
<body>
<form action="uploadFileAction.php" method="post" enctype="multipart/form-data" name="frmUpload">
<table id="tabFileup" align="center" width="80%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="45%"><div align="center">Server</div></td>
<td width="55%"><input name="txtServer" type="text" /></td>
</tr>
<tr>
<td><div align="center">UserName</div></td>
<td colspan="2"><input name="txtUser" type="text" /></td>
</tr>
<tr>
<td><div align="center">Password</div></td>
<td colspan="2"><input name="txtPass" type="password" /></td>
</tr>
<tr>
<td><div align="center">Upload file</div></td>
<td colspan="2"><input name="fileImage[]" type="file" /><a href="#" onclick="addFile();">add another</a></td>
</tr>
<tr>
<td>
<div align="center">
<input name="btnSubmit" type="submit" value="submit" />
</div></td>
<td colspan="2"><input name="btnReset" type="reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
<?php
if(isset($_FILES['file']['tmp_name']))
{
// Number of uploaded files
$num_files = count($_FILES['file']['tmp_name']);
/** loop through the array of files ***/
for($i=0; $i < $num_files;$i++)
{
// check if there is a file in the array
if(!is_uploaded_file($_FILES['file']['tmp_name'][$i]))
{
$messages[] = 'No file uploaded';
}
else
{
// copy the file to the specified dir
if(@copy($_FILES['file']['tmp_name'][$i],$upload_dir.'/'.$_FILES['file']['name'][$i]))
{
/*** give praise and thanks to the php gods ***/
$messages[] = $_FILES['file']['name'][$i].' uploaded';
}
else
{
/*** an error message ***/
$messages[] = 'Uploading '.$_FILES['file']['name'][$i].' Failed';
}
}
}
}
?>
Friday, May 13, 2011
Thursday, May 12, 2011
Friday, May 6, 2011
Wednesday, May 4, 2011
Ajax cross-browser XmlHttpRequest
function sendRequest(url,callback,postData) {
var req = createXMLHTTPObject();
if (!req) return;
var method = (postData) ? "POST" : "GET";
req.open(method,url,true);
req.setRequestHeader('User-Agent','XMLHTTP/1.0');
if (postData)
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
req.onreadystatechange = function () {
if (req.readyState != 4) return;
if (req.status != 200 && req.status != 304) {
// alert('HTTP error ' + req.status);
return;
}
callback(req);
}
if (req.readyState == 4) return;
req.send(postData);
}
var XMLHttpFactories = [
function () {return new XMLHttpRequest()},
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];
function createXMLHTTPObject() {
var xmlhttp = false;
for (var i=0;i<XMLHttpFactories.length;i++) {
try {
xmlhttp = XMLHttpFactories[i]();
}
catch (e) {
continue;
}
break;
}
return xmlhttp;
}
Tuesday, May 3, 2011
Mod Rewrite syntax
The key to good mod rewritting is patterns. Patterns in your urls are how we are going to distinguish what to rewrite and what not to rewrite. We'll get to that later, first we'll need to go over the basics of the mod rewrite syntax.
How to Use Mod_rewrite For URL Rewriting in Apache
RL Rewriting is the process of manipulating an URL or a link, which is send to a web server in such a way that the link is dynamically modified at the server to include additional parameters and information along with a server initiated redirection. The web server performs all these manipulations on the fly so that the browser is kept out of the loop regarding the change made in URL and the redirection.
URL Rewriting can benefit your websites and web based applications by providing better security, better visibility or friendliness with Search Engines and helps in keeping the structure of the website more easy to maintain for future changes.
You can read about the theory and benefits of URL Rewriting from my Previous article, which can be accessed from here. In this article we will be taking a look at how we can implement URL Rewriting on an Apache based web server environment using the mod_rewrite module for Apache.
Captcha image verification
A good way to avoid automatic form submissions when creating a web form is to add some kind of verification. One of the best ways is to use an image verification, called also captcha. What it does is to dynamically create an image with a random string displayed on it. Then visitor is asked to type that string in a text field and once the form is submitted it checks if the string on the image matches the one inputted by the user. Because there is no easy way to read a text from an image (image recognition) this is a good way to protect your web forms from spammers.
For doing this CAPTCHA I would suggest using a session variable where you store the string generated and displayed on that dynamically generated image.
For doing this CAPTCHA I would suggest using a session variable where you store the string generated and displayed on that dynamically generated image.
Subscribe to:
Comments (Atom)
Bind Some Event to Element and trigger that function when click the element
Scenario: Suppose if we used same click event function in various web pages. if you want do some logic some page button for that need to re...
-
Find highcharts which are loaded in the page and then convert chart into png using jquery Charts are loaded through the ajax See the e...