Hi, I am new to Webix (I used to use EXT JS and now consider to switch to Webix). I have troubles in working on file upload. File upload does not work at all. Can you look at and help me out? I follow an example from webix.
-------- my client side code -------------
webix.ui({
maxWidth:320,
view:"form", id:"myform",
elements:[
{ view:"text", label:"Title", labelPosition:"top", name:"title" },
{ view:"button", label:"Save", type:"form", click:save_form },
{
view:"uploader", upload:"pro_cancel.php",
id:"upl1", name:"uploader",
value:"Add documents",
link:"doclist", autosend:false
},
{ view:"list", scroll:false, id:"doclist", type:"uploader" }
]
});
$$("$text1").focus();
function save_form(){
//send files to server side
$$("upl1").send(function(){
//getting file properties
$$('upl1').files.data.each(function(obj){
var status = obj.status;
var name = obj.name;
if(status=='server'){
var sname = obj.sname; //came from upload script
webix.message("Upload: "+status+" for "+ name+" stored as "+sname );
}
else{
webix.message("Upload: "+status+" for "+ name);
}
});
//after that send form
webix.ajax().post(
"pro_cancel.php",
$$("myform").getValues(),
function(text){
//show server side response
webix.message(text);
}
);
});
}
--------- my procancel.php -----------
<?php
ini_set('max_execution_time', 120);
$destination = realpath('/data/files'); //my folder
if (isset($_FILES['uploader'])){
$file = $_FILES['uploader'];
$filename = $destination."/".preg_replace("|[\\\\\\/]|", "", $file["name"]);
$sname = md5($file["name"]);
//check that file name is valid
if ($filename !== "" && !file_exists($filename)){
move_uploaded_file($file["tmp_name"], $filename);
$res = array("status" => "server", "sname" => $sname);
} else {
$res = array("status" => "error");
}
echo json_encode($res);
}
?>