tags:

views:

521

answers:

2

Hi, I'm new in flex.i face a huge problem of the filereference class using the upload function. Actually i want to send the folderLocation variable with fileReference.upload(). Below i try to describe my strategy.Please help me with code correction.

var folderLocation : String = "photos/myUniqueFolder/";

private var serverSideScript:String = "http://localhost/project/phpFlexMechanism/upload.php"; urlRequest = new URLRequest(serverSideScript);

fileReferenceList.addEventListener(Event.SELECT, fileSelectedHandler);

private function fileSelectedHandler(event:Event):void { // upload the file to the server side script fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler); fileReference.upload(urlRequest); }

In php i use this to get the the file and uploaded

$folder = $_POST['folder'];

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

move_uploaded_file($tempFile, "../user/$folder/uploadImages/" . $fileName);

But how can i send the "folder" thgouth the "upload reference".

+1  A: 

I would think that, since you FileReference needs a URLRequest, you would be able to piggy back that information through the URLRequest itself by using the flash.net.URLVariables object.

I've not had time to test this, but have you tried:

// put this right after you instantiate urlRequest;
var urlVars:URLVariables = new URLVariables();
urlVars.targetFolder     = folderLocation;
urlRequest.method        = "post";
urlRequest.data          = urlVar;

That should let you do:

//replace your last line with these two.
$folder = $_REQUEST[ "targetFolder" ];
move_uploaded_file($tempFile, "../user/$folder/uploadImages/" . $fileName);

in PHP.

Christopher W. Allen-Poole
sorry for late.Thank you very much for your reply.
Mahedi
A: 

the easiest thing you can do is just send it through with a get header in the upload function

so the code looks as follows

private var serverSideScript:String = "http://localhost/project/phpFlexMechanism/upload.php?extraVar=value&extraVarB=value2";

fileReference.upload(urlRequest);

then in the php script you just use $_GET['extraValue'] $_GET['valueVarB']

hope that helps

Regards Mark

markblue777
Thank you very much for you reply.Sorry for late.
Mahedi