0
votes

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

1
I voted to close as this is "overly board". - JeffryHouser
+1 I upvoted as I felt the downvoter to this question didn't give OP the chance to elaborate. @Flex60460 with that said, please elaborate. - Taurayi
Start by showing us what you got. - Rob Fox

1 Answers