Download the component, are very Variable

Hi all.

I tried to get a component upload work for a while now, but have some trouble to get one to do what I need.  Recently, I found a component that does one thing, pretty much everything I want to bar spend an additional variable to the PHP script so I can name the files something unique.

My Flex code is-

<? XML version = "1.0" encoding = "utf-8"? >
" < = xmlns:fx s:Application ' http://ns.Adobe.com/MXML/2009 "
xmlns:s = "library://ns.adobe.com/flex/spark".
xmlns:MX = "library://ns.adobe.com/flex/mx".
creationComplete = "init ()" width = "600" height = "300" > "
< fx:Script >
<! [CDATA]

private var urlRequest:URLRequest;
private var fileReferenceList:FileReferenceList;
private var serverSideScript:String = " " http://www.davidtest.webcastglobal.com/upload/upload.php ";
[Bindable] public var ID:String;

private function init (): void {}
urlRequest = new URLRequest (serverSideScript);
fileReferenceList = new FileReferenceList();
fileReferenceList.addEventListener (Event.SELECT, fileSelectedHandler);
}

private function uploadFile (): void {}
fileReferenceList.browse ();
}

private void fileSelectedHandler(event:Event):void {}
var fileReference:FileReference;
var fileReferenceList:FileReferenceList = FileReferenceList (event.target);
var fileList:Array = fileReferenceList.fileList.

Download the first file that the user chose
fileReference = FileReference(fileList[0]);

Download the file to the script on the server side
fileReference.addEventListener (Event.COMPLETE, uploadCompleteHandler);
fileReference.upload (urlRequest);

update the status text
statusText.text = "Loading"... » ;


}

private void uploadCompleteHandler(event:Event):void {}
statusText.text = ' uploaded file: "+ event.target.name;»
}

[]] >
< / fx:Script >

< s:BorderContainer width = "300" height = "96" horizontalCenter = red '0' = '0' >
< mx:Label text = 'upload your CV"fontWeight = horizontalCenter"bold"="0"top ="10"/ >
< text mx:Label = "choose a file... '. "id ="statusText"horizontalCenter ="0"top ="35"/ >
< mx:Button click = "uploadFile (); ' label = horizontalCenter "Upload File" = "0" low = "10" / > ".
< / s:BorderContainer >

< / s:Application >

While my PHP code it

<? PHP

$tempFile = $_FILES ['Filedata'] ['tmp_name'];
$fileName = $_FILES ['Filedata'] ['name'];
$fileSize = $_FILES ['Filedata'] ['size'];
$id = $_POST ['id']

$newName = '$id'.'. doc';
move_uploaded_file ($tempFile, ".") / ». $newName);

? >

What I try to do is, when the user clicks the "Upload" button on the flex application file, after that they choose a file, it currently downloads this file using the given file name.  But what I want to do, is to pass the variable "ID" for the PHP and use as file name instead.

Im a little confused on how to do it?  I don't know where to include the code for the 'ID', normally I am occupied with HTTPSservice where you declare these things in the service.


Any help would be great. !

You should be able to add a parameter using URLVariables, then change your function init to something like:

private function init (): void {}
urlRequest = new URLRequest (serverSideScript);
var variables: URLVariables = new URLVariables();
variables.myFileName = "flexponential";
urlRequest.data = variable;
fileReferenceList = new FileReferenceList();
fileReferenceList.addEventListener (Event.SELECT, fileSelectedHandler);
}

And then in your PHP file you should be able to access these data through the post variable.

$myFileName = $_POST ['myFileName'];

Tags: Flex

Similar Questions

Maybe you are looking for