Created
May 18, 2022 17:35
-
-
Save MohcinBN/1f99b4823c87e9cb6a22963e1381d062 to your computer and use it in GitHub Desktop.
CSV TO XML using PHP, Ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<!-- Bootstrap CSS --> | |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> | |
<title>SCV To XML</title> | |
<style> | |
.card { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
-webkit-transform: translate(-50%, -50%); | |
} | |
#xmlresult { | |
margin: 9px 0 0 0; | |
text-align: center; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- <form action="csvToxml2.php" method="post" enctype="multipart/form-data"> | |
<input type="file" name="csv" id="csv"> | |
<input type="submit" value="Export"> | |
</form> --> | |
<div class="container"> | |
<div class="row"> | |
<div class="card" style="width: 50%; margin: 0 auto; padding: 38px;"> | |
<div class="col-md-8 mx-auto"> | |
<form action="csvToxml2.php" method="post" enctype="multipart/form-data" id="upload_csv_form"> | |
<!-- <input type="file" name="csv" id="file" value="" /> --> | |
<div class="mb-3"> | |
<input class="form-control" type="file" id="file" name="file"> | |
</div> | |
<input id="submit" type="submit" name="submit" value="Generate XML File" class="btn btn-success" style="width: 100%;" /> | |
</form> | |
<div id='xmlresult' style="display: none;"> | |
<a href="/phpscripting/sitemap.xml" download rel="noopener noreferrer" target="_blank"> | |
Download Your Generated XML | |
</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<!-- Option 1: Bootstrap Bundle with Popper --> | |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$('#upload_csv_form').on("submit", function(e){ | |
e.preventDefault(); | |
$.ajax({ | |
url:"http://localhost/phpscripting/csvToxml2.php", | |
method:"POST", | |
data:new FormData(this), | |
contentType:false, | |
cache:false, | |
processData:false, | |
success: function(data){ | |
console.log("Xml Created"); | |
$(function() { | |
$("#xmlresult").show(); | |
}); | |
}, | |
error: function(data) { | |
alert("Xml NOT Created"); | |
} | |
}) | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment