0
Please Help Me, I've make upload file XLS Format and want to post using S.AJAX
<span class="btn btn-primary btn-file"><span class="fileupload-new">Upload Penerima</span><input type="file" id="xlsfile"/></span>
<span class="fileupload-preview"></span>
<button type="button" class="btn btn-primary">Download Format</button>
<form class="navbar-form navbar-center">
<textarea name="jmltextarea" id="jmltextarea" class="form-control" style="min-width: 100%" rows="15" id="comment"></textarea>
</form>
<form class="navbar-form navbar-right">
<button type="button" class="btn btn-primary btn-right-side" style="margin-right:15px;" id="kirim">Kirim</button>
</form>
and post using javascript like this
$("#kirim").click(function() {
var jmltextarea = $("#jmltextarea").val();
var xlsfile = $("#xlsfile").val();
$.ajax ({
type:"POST",
url:"proses_kirim.php",
data: "jmltextarea=" + jmltextarea + "&xlsfile=" + xlsfile,
success: function(data){
$("#info").html(data);
}
});
});
when post i want to read xls file and check to my database like this : "proses_kirim.php"
<?php
include "koneksi/koneksi.php";
include 'excel_reader2.php';
$xlsfile=basename($_FILES['xlsfile']['name']) ;
move_uploaded_file($_FILES['xlsfile']['tmp_name'], $xlsfile);
$jmltextarea=($_POST['jmltextarea']);
chmod($_FILES['xlsfile']['name'],0777);
$data = new Spreadsheet_Excel_Reader($_FILES['xlsfile']['name'],false);
$baris = $data->rowcount();
for($i=2; $i<=$baris; $i++){
$npp = $data->val($i,2);
echo $npp;
$sql = "SELECT id FROM pbk WHERE NPP = '$npp'";
$ada=mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($ada)>0)
{
$kirim_pesan = mysql_query("insert into outbox (DestinationNumber, TextDecoded, CreatorID)
values('$npp', 'tes', 'Gammu')");
}
else
{
?>
<script type="text/javascript">
showNotification({
message: "<?php echo "gagal dikirim" ?>",
type: "error",
autoClose: true,
duration: 2
});
</script>
<?php
}
}
unlink($_FILES['xlsfile']['name']);
?>
i use excel reader to read xls file, my xls file like this :
|NO|NPP|
|1|DD00100|
|2|DD09090|
please help me, how to post xls file, check into database and insert into database. thank you for your help.
1Programming questions are off-topic on superuser. They can be asked on stackoverflow, however your question isn't clear, please read stackoverflow's help center to learn how you could improve it before asking it there. – Máté Juhász – 2016-10-08T12:07:45.000
my question is : how to get value from xls file and post it using $.ajax after that i want to insert into my database.
i use var xlsfile = $("#xlsfile").val(); but failed. – Donesa Rucci – 2016-10-08T12:12:48.670