|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /var/www/html/pathumthani_eoffice/application/bin/auction_news/fileupload/ |
Upload File : |
<html>
<head>
<title>Ajax File Uploader Plugin For Jquery</title>
<link href="ajaxfileupload.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ajaxfileupload.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#Close").click(function(){
window.close();
}) ;
$("#Upload").click(function(){
if($("#fileToUpload").val()==""){
alert("กรุณาเลือกไฟล์ก่อน");
return false;
}
else if($("#desc").val()==""){
alert("กรุณากรอกคำอธิบายไฟล์");
return false;
}
ajaxFileUpload("ADD","")
})
})
function ajaxFileUpload(state,id)
{
//if(state=="LOAD"){
document.form.Fstatus.value=state;
document.form.chkedit.value=id;
// }
var ElementIdArray= new Array(4)
ElementIdArray[0]={Name:"fileToUpload",Type:"File"}
ElementIdArray[1]={Name:"desc",Type:"Text"}
ElementIdArray[2]={Name:"idindex",Type:"Hidden"}
ElementIdArray[3]={Name:"Fstatus",Type:"Hidden"}
ElementIdArray[4]={Name:"chkedit",Type:"Checkbox"}
$("#loading")
.ajaxStart(function(){
$(this).show();
})
.ajaxComplete(function(){
$(this).hide();
});
$.ajaxFileUpload
(
{
url:'doajaxfileupload.php',
secureuri:false,
ElementId:ElementIdArray,
dataType: 'json',
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
document.getElementById('UploadStatus').innerHTML=data.error;
}else
{
Showlistitem( data.msg);
document.form.desc.value=id;
}
}
},
error: function (data, status, e)
{
alert( status + " "+data.responseText)
}
}
)
return false;
}
function Showlistitem(ListItem)
{
var str="";
for(i=0;i<ListItem.length;i++){
str+= "<ul>"+(i+1)+". "+ ListItem[i].desc +" <a href='#'> <img border=0 src=\"../../../images/b_drop.png\"/ onClick=\"DELFile('"+ ListItem[i].id +"')\"></a></ul>"
}
document.getElementById('listFile').innerHTML=str;
}
function DELFile(ID){
if(confirm('ต้องการลบรูปนี้หรือไม่')){
ajaxFileUpload('DEL',ID)
}
}
</script>
</head>
<body onLoad="ajaxFileUpload('LOAD','')">
<div id="wrapper">
<div id="content">
<h1><img src="../images/project1.gif" width="52" height="52" /> FileUpload </h1>
<form name="form" action="" method="POST" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" class="tableForm" width="500px">
<thead>
<tr>
<th width="112" align="left"> </th>
<th width="441" align="left"> </th>
</tr>
</thead>
<tbody>
<tr>
<td align="right" class="font_aption">เลือกไฟล์ :</td>
<td class="font_err"><input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input">*</td>
</tr>
<tr>
<td align="right" class="font_aption">คำอธิบายไฟล์:</td>
<td class="font_err"><input name="desc" type="text" id="desc" size="57" maxlength="25">
*</td>
</tr>
<tr>
<td> </td>
<td class="font_err">* ไฟล์ไม่ควรใหญ่เกิน 10M ภาพขนาดไม่เกิน 600x800</td>
</tr>
<tr>
<td> </td>
<td><img id="loading" src="loading.gif" style="display:none;">
<input type="hidden" name="idindex" id="idindex" value="<?=$indexid?>">
<input type="hidden" name="chkedit" id="chkedit" >
<input type="hidden" name="Fstatus" id="Fstatus" value="">
<button name="Upload" id="Upload" style="width:50px; height:20px; font-size:12px" >Upload</button>
<button name="Close" id="Close" style="width:50px; height:20px; font-size:12px" >Close</button>
</td>
</tr>
<tr>
<td> </td>
<td></td> </tr>
</tbody>
<tfoot>
<tr>
<td> </td>
<td> <div id="UploadStatus"></div>
<div id="listFile" class="ShowList"></div></td>
</tr>
</tfoot>
</table>
</form>
</div>
</body>
</html>