form and ajax code
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>Untitled Document</title>
- <script language="javascript">
- var xmlHttp
- function uploadfile()
- {
- //;
- //var i = 0;
- // This little bit loops through all the elements in the form, locates the
- // file input field, and extracts the file name of the file being uploaded.
- var fileName = document.form1.uploadedfile.value;
- if (fileName.indexOf('/') > -1) {
- fileName = fileName.substring(fileName.lastIndexOf('/')+1, fileName.length);
- } else {
- fileName = fileName.substring(fileName.lastIndexOf('\\')+1, fileName.length);
- }
- //Since there can only be one file per form for this script, we'll exit the loop here.
- //var str = ;
- alert(fileName);
- //form1.submit();
- //var str = document.form1.tosingleemail.value;
- //var grp = document.form1.mailgroup.value;
- //alert(grp);
- xmlHttp=GetXmlHttpObject()
- if (xmlHttp==null)
- {
- alert ("Browser does not support HTTP Request")
- return
- }
- var url="uploader.php"
- url=url+"?q="+fileName
- url=url+"&sid="+Math.random()
- xmlHttp.onreadystatechange=stateChanged
- xmlHttp.open("GET",url,true)
- xmlHttp.send(null)
- }
- function stateChanged()
- {
- if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
- {
- document.getElementById("msg").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;
- }
- function subject1()
- {
- if(document.form1.subject.value == "")
- {
- alert('Subject is missing!');
- return false;
- }
- else
- {
- return true;
- }
- }
- </script>
- </head>
- <body>
- <form enctype="multipart/form-data" name="form1" action="" method="POST">
- <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
- Choose a file to upload: <input name="uploadedfile" id="uploadedfile" type="file" /><br />
- <input type="button" onclick="uploadfile()" value="Upload File" />
- </form>
- <div id="msg"></div>
- </body>
- </html>
[PHP]<?php
$q=$_GET["q"];
$target_path = "uploads/";
echo $target_path = $target_path . basename($q);
//$_FILES['uploadedfile']['tmp_name'];
//$_FILES['uploadedfile']['tmp_name'];
$p = 'C:\Program Files\xampp\tmp\php168.tmp';
if(move_uploaded_file($p, $target_path)) {
echo "The file ". basename($q).
" has been uploaded";
} else{
echo "<br>There was an error uploading the file, please try again!";
}
?>[/PHP]
please help me to figure out the problem