Flash receiving status of file write from PHP?

陌路散爱 提交于 2019-12-24 18:12:56

问题


I am trying to make a simple Flash ActionScript3 program that saves some text to a text file (on my server) via a PHP script. I want the Flash program to be able to detect if the PHP script fails to write. Right now I'm just trying to get Flash to trace a status received from PHP. My below code is based on a few examples I've found online.

Here is my Flash code:

import flash.net.*;
import flash.events.*;

var varLoader:URLLoader = new URLLoader;
var varURL:URLRequest = new URLRequest("http://xxxxxxxx/outputTest.php");
var submittedData:URLVariables=new URLVariables();
varURL.data = submittedData;
varURL.method = URLRequestMethod.POST;

submittedData.inputData = "ThisIsTheDataToBeSaved";
submittedData.FileName = "ThisIsTheFileName";
varLoader.addEventListener(Event.COMPLETE, fxnDoneSaving);
varLoader.load(varURL);

function fxnDoneSaving(evt:Event):void{
    trace("Done saving.");
    trace("Write status: "+String(evt.target.data.WasWritingSuccessful));
}

Here is my PHP code:

<?php

$receivedFromFlashData = $_POST['inputData']; 
$receivedFromFlashFileName = $_POST['FileName']; 

$filename = $receivedFromFlashFileName . ".txt";
$myTextFileHandler = fopen($filename,"w"); 

if($myTextFileHandler)
    {$writeInTxtFile = @fwrite($myTextFileHandler,"$receivedFromFlashData");}      

fclose($myTextFileHandler); 

if ($writeInTxtFile)
    {echo "WasWritingSuccessful=success";}
else
    {echo "WasWritingSuccessful=failure";}

?>

When Flash gets to the final trace statement, I get the following error: "ReferenceError: Error #1069: Property WasWritingSuccessful not found on String and there is no default value."

Please help me understand what I'm doing wrong? thanks!


回答1:


You need to specify the dataFormat of varLoader like so: varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;



来源:https://stackoverflow.com/questions/13734969/flash-receiving-status-of-file-write-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!