I’m trying to upload an image file to another server and load the image into my flash application. I’ve modified crossdomain.xml as to allow the php to do the uploading to the other server.
var fileRef:FileReference = new FileReference();
fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandlerN);
//fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, completeHandlerN);
uploadBtn.addEventListener(MouseEvent.MOUSE_DOWN, upload);
function upload(event:Event):void
{
try
{
var success:Boolean = fileRef.browse();
}
catch (error:Error)
{
trace("Unable to browse for files.");
}
}
function selectHandler(event:Event):void
{
var urlRequest:URLRequest = new URLRequest("proxy.php?");
var urlParams:URLVariables = new URLVariables();
urlParams.proxyaction = "assign";
urlRequest.method = URLRequestMethod.GET;
urlRequest.data = urlParams;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, serverResponse);
loader.load(urlRequest);
}
function serverResponse(e:Event):void {
var loader:URLLoader = URLLoader(e.target);
var variables:URLVariables = new URLVariables(loader.data);
txtServer.text = variables.q; //getServer Num
//serverNum = variables.q; // UNCOMMENT WHEN SERVER 4 IS ALSO IMPLEMENTED
registerAndUpload();
}
function registerAndUpload()
{
filename = fileRef.name;
txtOutput.text = filename;
var request:URLRequest = new URLRequest("otherserver.com/upload.php");
try
{
fileRef.upload(request);
}
catch (error:Error)
{
trace("Unable to upload file.");
}
}
function completeHandlerN(evt:Event):void
{
trace("uploaded");
imgBefore.source = "otherserver.com/files/" + filename;
txtOutput.text = "File uploaded";
txtOutput.text = "*"; //get Registerd ID Num
txtOutput.appendText(evt.target.data.q+"*");
txtOutput.appendText("after");
}
The problem is this: I am ABLE to upload the image to the other server - it is present there, and LOAD it onto the flash movie using
imgBefore.source = "otherserver.com/files/" + filename;
However I cannot access the echo back data. Meaning
txtOutput.appendText(evt.target.data.q+"*");
does not do anything.
In the php file I do the upload first:
if(!is_dir("./files")) mkdir("./files", 0777);
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
chmod("./files/".$_FILES['Filedata']['name'], 0777);
$q='test';
$returnVars['q'] = $q;
$returnString = http_build_query($returnVars);
echo $returnString;
I never get the echo back. Any suggestions. The echo should be executed as I’m waiting on Event.Complete!
Any suggestions