Demo code for upload file

Find code here before you post.

Demo code for upload file

Postby linb » Thu May 30, 2013 3:48 am

   
Class('App', 'xui.Com',{
Instance:{
iniComponents:function(){
// [[Code created by CrossUI RAD Tools
var host=this, children=[], append=function(child){children.push(child.get(0))};

append(
(new xui.UI.SLabel)
.setHost(host,"slabel1")
.setLeft(30)
.setTop(44)
.setCaption("Select your file: ")
);

append(
(new xui.UI.SButton)
.setHost(host,"sbutton3")
.setLeft(320)
.setTop(40)
.setCaption("Upload it")
.onClick("_sbutton3_onclick")
);

append(
(new xui.UI.ComboInput)
.setHost(host,"upload")
.setReadonly(true)
.setLeft(130)
.setTop(40)
.setWidth(180)
.setType("file")
.setValue("Select a file ...")
);

return children;
// ]]Code created by CrossUI RAD Tools
},
_sbutton3_onclick:function (profile, e, src, value) {
var file=this.upload.getUploadObj();
if(file){
xui.request('request.php',{file:file},function(rsp){
xui.alert(rsp.data.message);
},function(errMsg){
xui.alert(errMsg)
}).start();
}
}
}
});
   


PHP back-end:

php code
<?php  
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
echo "<script>window.name=\"{id:'".$_POST["id"]."',data:{message:'ok'}}\"</script>"
?>
linb
Site Admin
 
Posts: 102
Joined: Thu Apr 25, 2013 6:51 am

Return to CrossUI Code Snaps

Who is online

Users browsing this forum: No registered users and 1 guest

cron