龙博3.0β源码SVN地址http://linb.googlecode.com/svn/trunk/jsLinb3.0
下载龙博3.0β源码包!    下载龙博3.0教程-入门篇 pdf 版!
返回列表 回复 发帖

上传文件示例

客户端jsLinb类:
  1. Class('App', 'linb.Com',{
  2.     Instance:{
  3.         iniComponents:function(){
  4.             // [[code created by jsLinb UI Builder
  5.             var host=this, children=[], append=function(child){children.push(child.get(0))};
  6.         
  7.             append((new linb.UI.SLabel)
  8.                 .host(host,"slabel1")
  9.                 .setLeft(40)
  10.                 .setTop(44)
  11.                 .setCaption("Select your file: ")
  12.             );
  13.             
  14.             append((new linb.UI.ComboInput)
  15.                 .host(host,"upload")
  16.                 .setLeft(140)
  17.                 .setTop(40)
  18.                 .setWidth(140)
  19.                 .setReadonly(true)
  20.                 .setType("upload")
  21.                 .setValue("Select a file ...")
  22.             );
  23.             
  24.             append((new linb.UI.SButton)
  25.                 .host(host,"sbutton3")
  26.                 .setLeft(290)
  27.                 .setTop(40)
  28.                 .setCaption("Upload it")
  29.                 .onClick("_sbutton3_onclick")
  30.             );
  31.             
  32.             return children;
  33.             // ]]code created by jsLinb UI Builder
  34.         },
  35.         _sbutton3_onclick:function (profile, e, src, value) {
  36.             var file=this.upload.getUploadObj();
  37.             if(file){
  38.                 // 请求服务的地址是request.php
  39.                 linb.request('request.php',{file:file},function(rsp){
  40.                     linb.alert(rsp.data.message);
  41.                 },function(errMsg){
  42.                     linb.alert(errMsg)
  43.                 }).start();
  44.             }
  45.         }
  46.     }
  47. });
复制代码
服务端request.php 的内容:
  1.   <?php  
  2. move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
  3. echo "<script>window.name=\"{id:'".$_POST["id"]."',data:{message:'ok'}}\"</script>"
  4.   ?>
复制代码
尊重彼此感受,善待体验工具,时时不忘召唤自己。
var file=this.upload.getUploadObj();

            if(file){

                // 请求服务的地址是request.php

                linb.request('request.php',{file:file},function(rsp){

                    linb.alert(rsp.data.message);

                },function(errMsg){

                    linb.alert(errMsg)

                }).start();

            }



在这里怎么做文件类型的判断(扩展名的判断)???????
append((new linb.UI.ComboInput)

                .host(host,"upload")

//这个控件在客户端不能做文件类型的判断吗?
这个与库无关,到网上一查就有答案了

var file=this.upload.getUploadObj();
linb.alert(file.value);
尊重彼此感受,善待体验工具,时时不忘召唤自己。
返回列表