我尝试将文件从本地系统上传到Web服务器。 我的应用程序是桌面应用程序,我使用php服务器。
查找下面的代码
在flex
var dropfiles:Array = evt.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
for each (var file:File in dropfiles){
var fileFormat:String = file.extension;
var fileUrl:String = file.url;
var fileName:String = file.name;
var fileDate:Date = file.creationDate;
var objAdd:Object= new Object();
objAdd.titre=fileName;
objAdd.date=fileDate;
objAdd.url=fileUrl;
DP_PAT_COURR_ENT.addItem(objAdd);
var myFileDir:String=getPatPath(monIdPatient);
var urlCopy:String = new urlManager().urlCourriersPatLoad()+myFileDir;
var rq:URLRequest = new URLRequest(new urlManager().urlService() + "upload.php");
rq.method = URLRequestMethod.POST;
var varphp:URLVariables = new URLVariables();
varphp.userID = monIdPatient;
varphp.url = myFileDir;
rq.data = varphp;
file.upload(rq, 'Filedata');
}
在PHP中
<?php
if(isset($_POST['myFileDir']))
$patRoot=$_POST['myFileDir'];
$file_temp = $_FILES['Filedata']['tmp_name'];
$file_name = $_FILES['Filedata']['name'];
$file_path = $_SERVER['DOCUMENT_ROOT'].$patRoot";
//checks for duplicate files
if(!file_exists($file_path."/".$file_name)) {
//complete upload
$filestatus = move_uploaded_file($file_temp,$file_path."/".$file_name);
if(!$filestatus) {
$success = "false";
array_push($errors,"Upload failed. Please try again.");
}
}
else {
$success = "false";
array_push($errors,"File already exists on server.");
}
echo $file_path;
使用这些代码消息“Error#2044:Unhandled IOErrorEvent:”出现在flex上。
感谢您的帮助
答案 0 :(得分:0)