|
|
|
Upload File text to Mssql โดยใช้ Ajax แล้ว ไม่ยอมส่งค่าไปให้อีกหน้าหนึ่ง |
|
|
|
|
|
|
|
มีปัญหา คือ มันไม่ยอมส่งค่า $("#fileCSV").val() ไปให้ อีกหน้าหนึ่ง อ่ะ คับ
Code (PHP)
<html>
<head>
<title>Upload File</title>
<script type="text/javascript" src="../../jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
function checkUpload()
{
//alert($("#fileCSV").val());
$.ajax({
url: "/module/hr/phpCSVMssqlUpload.php",
type: "POST",
data: { fileCSV:$("#fileCSV").val()},
success: function(response)
{
if(response == 'true')
{
$("#show").html('<font style=" font-size:16px; font-weight:bold">'+response+'</font>');
}
else {$("#show").html('<font style=" font-size:16px; font-weight:bold">'+response+'</font>');}
}
});
}
</script>
</head>
<body>
<form action="phpCSVMssqlUpload.php" method="post" enctype="multipart/form-data" id="fm_UploadFile">
<input name="fileCSV" type="file" id="fileCSV">
<input name="btnSubmit" type="submit" id="btnSubmit" value="Submit">
<input name="test" type="button" id="test" value="test" onClick="checkUpload();">
</form>
<p id="show"></p>
</body>
</html>
นี่ไฟล์ phpCSVMssqlUpload.php
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & CSV To MySQL</title>
</head>
<body>
<?
include'../../DB/conn.php';
move_uploaded_file($_FILES["fileCSV"]["tmp_name"],$_FILES["fileCSV"]["name"]); // Copy/Upload CSV
//$temp = array();
$today = date("Y/m/d");
$objCSV = fopen($_FILES["fileCSV"]["name"], "r");
if ($objCSV){
$i=0;
while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
$i++;
$temp = explode(" ",$objArr[0]);
$strSQL = "insert into TimeRecord (EmpNum,Date,Time,Machine,DateTimeRecord)
values ('".$temp[0]."','".$temp[2]."','".$temp[3]."','".$temp[4]."','".$today."')";
$objQuery = @mssql_query($strSQL);
}
fclose($objCSV);
$respone = "true";
}
else {$respone = "false";}
echo $respone;
?>
</table>
</body>
</html>
Tag : PHP, Ms SQL Server 2005, Ajax
|
|
|
|
|
|
Date :
2013-11-13 08:41:42 |
By :
wirunmoy |
View :
722 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|