先看看服务器的文件:

upload.php 最简单的文件处理:

<?php

$tempFile = $_FILES['pic']['tmp_name'];
$fileName = $_FILES['pic']['name'];
$fileSize = $_FILES['pic']['size'];

move_uploaded_file($tempFile, $fileName);

echo "Uploaded $fileName";


在adobeAir里面,建立一个上传的流程:

//文件上传
function callback_for_upload_progress(event) {
  var loaded = event.bytesLoaded;
  var total = event.bytesTotal;
  var pct = Math.ceil( ( loaded / total ) * 100 );
  air.trace('Uploaded ' + pct.toString() + '%');
}
function callback_for_upload_finish(event) {
  air.trace(event.data); // output of server response to AIR dev console
}
function upload_file( pictureFile ){
  var url = "http://www.aslibra.com/tmp/php/weibo/upload.php";
  var variables = new air.URLVariables();
  variables.op = 'upload';

  // set params for http request
  var tmpRequest = new air.URLRequest(url);
  tmpRequest.method = air.URLRequestMethod.POST;
  tmpRequest.contentType = 'multipart/form-data';
  // assigning variables to request
  tmpRequest.data = variables;
  air.sendToURL(tmpRequest);

  // attach events for displaying progress bar and upload complete
  pictureFile.addEventListener(air.ProgressEvent.PROGRESS, callback_for_upload_progress);
  pictureFile.addEventListener(air.DataEvent.UPLOAD_COMPLETE_DATA, callback_for_upload_finish);

  // doing upload request to server
  pictureFile.upload(tmpRequest, 'pic', false);
}


注:pictureFile是一个文件对象

var pictureFile = new air.File("文件全路径");
upload_file( pictureFile );


结合拖放事件,那就是拖进窗口就上传了,很便捷

1 Upload to server with Adobe AIR and JavaScript
2 Desktop Image Uploaders Using Adobe AIR and JavaScript


原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
mbvpianpa Email
2011/10/13 12:56
我的板块怎么没了。
分页: 1/1 第一页 1 最后页
发表评论
AD
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写
 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐