0

I try to upload file from local system to web server. My application is desktop application and I work with php server.

Find below my code

In 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');            

        }

In 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;

With those code message "Error #2044: Unhandled IOErrorEvent:" appear on flex.

Thanks for helping

Flex60460
  • 933
  • 2
  • 18
  • 49

1 Answers1

0

There are many examples out there. http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/

b-ryce
  • 5,752
  • 7
  • 49
  • 79