I have a dijit form that uploads an excel file and sends it via post to upload.php that will load the data of this file to database. The problem I have is that the file is not sent. I work with dojo 1.10.
I've tried xhrPost and iframe but didn't succeed and I didn't understand how to do it and what type of data I should send (is it text??).
<head>
<link rel="stylesheet" href="./dojoroot/dijit/themes/claro/claro.css">
<script>dojoConfig = {parseOnLoad: true}</script>
<script src='./dojoroot/dojo/dojo.js'></script>
<script>
require(["dojo/parser", "dijit/form/Form", "dijit/form/Button", "dojox/form/Uploader", "dojox/form/uploader/plugins/IFrame","dojox/form/uploader/FileList", "dojo/request/iframe", "dojo/domReady!"]);
function sendForm(){
var form = dojo.byId("uploadForm");
dojo.connect(form, "onsubmit", function(event){
dojo.stopEvent(event);
var xhrArgs = {
form: dojo.byId("uploadForm"),
handleAs: "text",
load: function(data){
dojo.byId("response").innerHTML = "Form posted.";
},
error: function(error){
dojo.byId("response").innerHTML = "Form posted.";
}
}
dojo.byId("response").innerHTML = "Form being sent..."
var deferred = dojo.xhrPost(xhrArgs);
});
}
dojo.ready(sendForm);
</script>
</head>
<div data-dojo-type="dijit/form/Form" id="uploadForm" action="upload.php" method="post" name="upload_excel" enctype="multipart/form-data">
<div>
<input data-dojo-type="dojox/form/Uploader" name="file" multiple="false" type="file" id="file" label="Browse" data-dojo-props="name:'file',showInput:'before',isDebug:true">
<input type="submit" id="submit" label="Upload" name="Import" dojoType="dijit/form/Button" />
<div id="files2" dojoType="dojox/form/uploader/FileList" uploaderId="file"></div>
</div>
</div>
In upload.php I have this:
if(isset($_POST["Import"])){
$filename = $_FILES["file"]["tmp_name"];
....
I read dojo documentation, but I couldn't get the point about how to solve my issue. I appreciate your help.
You have an error inside the form. The input tag with name
importis actually a button and will not have a value when you send this to the server. Soisset($_POST["Import"])will return false.So removing this check will do the job.