Login   Register  
PHP Classes
elePHPant
Icontem

File: uploader.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Er. Rochak Chauhan  >  AJAX File Uploader  >  uploader.js  >  Download  
File: uploader.js
Role: Auxiliary data
Content type: text/plain
Description: javascript file
Class: AJAX File Uploader
Browse files uploaded without page reloading
Author: By
Last change: Fixed a bug to display properly on IE.
Date: 2009-03-10 10:02
Size: 1,390 bytes
 

Contents

Class file image Download
var http=createRequestObject();
var uploader="";
var uploadDir="";
var dirname="";
var filename="";
var timeInterval="";
var idname="";
var uploaderId="";

function createRequestObject() {
    var obj;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
    	return new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
    	return new XMLHttpRequest();
    }   
}
function traceUpload() {
   http.onreadystatechange = handleResponse;
   http.open("GET", 'imageupload.php?uploadDir='+uploadDir+'&dirname='+dirname+'&filename='+filename+'&uploader='+uploader); 
   http.send(null);   
}
function handleResponse() {
	if(http.readyState == 4){
		var response=http.responseText; 
		if(response.indexOf("File uploaded") != -1){
			clearInterval(timeInterval);
			//document.getElementById('loading'+idname).innerHTML="";
		}
        document.getElementById(uploaderId).innerHTML=response;
    }
    else {
    	document.getElementById(uploaderId).innerHTML="Uploading File. Please wait...";
    }
}
function uploadFile(obj, dname) {
	uploadDir=obj.value;
	idname=obj.name;
	dirname=dname;
	filename=uploadDir.substr(uploadDir.lastIndexOf('\\')+1);
	uploaderId = 'uploader'+obj.name;
	uploader = obj.name;
	document.getElementById('formName'+obj.name).submit();
	timeInterval=setInterval("traceUpload()", 1500);
}