Question

I have a problem with the filereference class using the upload function. I want to send the folderLocation variable with fileReference.upload(). Below I try to describe my strategy.

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 through the "upload reference"?

Was it helpful?

Solution

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.

OTHER TIPS

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']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top