Copy link to clipboard
Copied
I have problem.
My AS3 code:
submit_btn.addEventListener(MouseEvent.CLICK, writeLine);
function writeLine(e:MouseEvent):void{
var my_vars:URLVariables = new URLVariables();
my_vars.kazkas1_t = kazkas1.text;
my_vars.kazkas2_t = kazkas2.text;
my_vars.kazkas3_t = kazkas3.text;
var my_url:URLRequest = new URLRequest("http://www.mesmylimbirzus.lt/app/id.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);
kazkas3.text = "Išsaugota";
}
and PHP code:
<?php
$myfile = fopen("test.txt", "a")
$current = ($_POST['kazkas1_t'] . " " . $_POST['kazkas2_t'] . $_POST['kazkas3_t'] .'\n');
fwrite($current .'\n');
?>
But i GET error:
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
WHAT IM DOING WRONG?
1 Correct answer
correct answer:
function writeLine(e:MouseEvent):void{
var my_url:URLRequest = new URLRequest("http://www.mesmylimbirzus.lt/app/id.php");
my_url.method = URLRequestMethod.POST;
my_url.data = "kazkas1_t="+kazkas1.text+"&kazkas2_t="+kazkas2.text+"&kazkas3_t="+kazkas3.text;
var my_loader:URLLoader = new URLLoader(); try { my_loader.load(my_url); } catch (error:Error) { trace("Unable to load requested document."); }
}
private function configureListeners(dispatcher:IEventDi
Copy link to clipboard
Copied
do you manage COMPLETE loader event?
Copy link to clipboard
Copied
Hm these scrips is all what I have.
Copy link to clipboard
Copied
try this and tell me if it works. Also use HTTPS instead of HTTP in production mode or anyone can catch your data on the fly
function writeLine(e:MouseEvent):void{
var my_url:URLRequest = new URLRequest("http://www.mesmylimbirzus.lt/app/id.php");
my_url.method = URLRequestMethod.POST;
my_url.data = "kazkas1_t="+kazkas1.text+"&kazkas2_t="+kazkas2.text+"&kazkas3_t="+kazkas3.text;
var my_loader:URLLoader = new URLLoader(); try { my_loader.load(my_url); } catch (error:Error) { trace("Unable to load requested document."); }
}
private function configureListeners(dispatcher:IEventDispatcher��void { dispatcher.addEventListener(Event.COMPLETE, completeHandler); dispatcher.addEventListener(Event.OPEN, openHandler); dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler); dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);}private function completeHandler(event:Event��void { var loader:URLLoader = URLLoader(event.target); trace("completeHandler: " + loader.data);}private function openHandler(event:Event��void { trace("openHandler: " + event);}private function progressHandler(event:ProgressEvent��void { trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);}private function securityErrorHandler(event:SecurityErrorEvent��void { trace("securityErrorHandler: " + event);}private function httpStatusHandler(event:HTTPStatusEvent��void { trace("httpStatusHandler: " + event);}private function ioErrorHandler(event:IOErrorEvent��void { trace("ioErrorHandler: " + event);}
Copy link to clipboard
Copied
No errors, but i dont get any string to my txt. Maby its php code wrong.
Copy link to clipboard
Copied
Or maby is the way to do the same without php just with as3 in AIR?
Copy link to clipboard
Copied
in your php check permission of the file you are opening.
must be allowed to write with php system user (usually nobody or www)
<?php
$fp =@ fopen("test.txt", "a") ;
if($fp){
$current = ($_POST['kazkas1_t'] . " " . $_POST['kazkas2_t'] . $_POST['kazkas3_t'] .'\n');
fwrite($current);
fclose($fp);
}else{
// answer to flash by something like varNamer=error to tell the flash client that something wrong happen
// or send and email to yourself to debug it
}
?>
AIR is something else, depend what you'd like to achieve, be clear of what you need thanks
Copy link to clipboard
Copied
OMG im so tired of that...
I have the same... No errors but my txt file is empty.
test.txt permisions is 777
I just need to write string from 3 textfields in to test.txt file and every time in the new line.
But 2 days im looking for simple thing.
I tried something like this:
import flash.fileSystem.*;
import flash.utils.ByteArray;
import flash.events.Event;
var file:File = new File("test.txt");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes("Hello World");
stream.close();
But its like madhouse. 10000 erors
Scene 1, Layer 'Layer 1', Frame 1, Line 1, Column 24 1172: Definition flash.fileSystem could not be found.
Scene 1, Layer 'Layer 1', Frame 1, Line 7, Column 10 1046: Type was not found or was not a compile-time constant: File.
Scene 1, Layer 'Layer 1', Frame 1, Line 8, Column 16 1046: Type was not found or was not a compile-time constant: FileStream.
Scene 1, Layer 'Layer 1', Frame 1, Line 7, Column 22 1180: Call to a possibly undefined method File.
Scene 1, Layer 'Layer 1', Frame 1, Line 8, Column 33 1180: Call to a possibly undefined method FileStream.
Scene 1, Layer 'Layer 1', Frame 1, Line 9, Column 23 1120: Access of undefined property FileMode.
I added all library paths but seems it not helped. AIRGLOBAL.SWC AIR 2,5; AIRGLOBAL.SWC AIR 23,0;
Copy link to clipboard
Copied
?Really thanks for your time and help but its not working:|
Copy link to clipboard
Copied
what's your application? AIR or Flash?
Copy link to clipboard
Copied
AIR aplication 😕
Copy link to clipboard
Copied
To debug it, check your php script to see if you receive the POST
like send an email to yourself with print_r($_POST,true) as body message
also the path of the text file you are opening with fopen must be absolute (with AIR it must start with file:// if local if I remember)
there is nothing complicated in what you wan to do.
the thing is you must find a easy way to debug your code from any step or you will lose a lot of time for nothing
Copy link to clipboard
Copied
Also, be aware of the sandbox violation, not remember how AIR manage it compared to flash
Copy link to clipboard
Copied
your AIR example does something different, it opens a LOCAL file from the client,
but your php script is on SERVER, so the text file must be on the server as well
and to write on it you must use an absolute path
Copy link to clipboard
Copied
on server app folder i have id.php and test.txt file. txt permisions 777. so why i gantb get string in text file. Seems it have to work
Copy link to clipboard
Copied
in email i get string it working good. But why i cant write string to txt file i dont understand
Copy link to clipboard
Copied
change also into the code I wrote
fwrite($current);
with
if(@fwrite($current)){
// ok
}else{
// debug issue
}
fclose($fp);
where is your text file?
Copy link to clipboard
Copied
[17-Apr-2018 11:15:56 UTC] PHP Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) in /home/mesmylimbirzus/public_html/app/id.php on line 5
i have error log file
Copy link to clipboard
Copied
depend many things since your text file is in the same folder of your PHP script which is a very serious security issue
- the web server does not allow to write to any file as long as it is exposed to public
- the folder containing your text file does not allow any execution
my advice.
move the text file out of the web root, somethin like /home/myData/blabla
make blabla own by the web server user (check your web server configuration)
you don't need 777 as long as the text file is own by the right user so the web server system user with 600 permissions
use absolute path to open it
fopen("/home/myData/blabla/myfile.txt","a");
I supposed you use "a" to append each line of text right?
Copy link to clipboard
Copied
I dont understand what you just said:DDD
Copy link to clipboard
Copied
PHP must finish always with a semicolon like ";"
if not php throw an error.
your php scrip has a code error, correct it and test again
and try your script URL directly with a browser to see if no error
Copy link to clipboard
Copied
so far so good, always check if any error from the web server log.
I just saw something that makes no sense
change
$current = ($_POST['kazkas1_t'] . " " . $_POST['kazkas2_t'] . $_POST['kazkas3_t'] .'\n');
to
$current = $_POST['kazkas1_t'] . $_POST['kazkas2_t'] . $_POST['kazkas3_t'].'\n';
always use the PHP cli from a terminal to be sure there is no PHP error
Copy link to clipboard
Copied
check the semi colons too!!!
$myfile = fopen("test.txt", "a")
to
$myfile = fopen("test.txt", "a"); <- !!!
Copy link to clipboard
Copied
My AIR code looks like this now:
submit_btn.addEventListener(MouseEvent.CLICK, writeLine);
function writeLine(e:MouseEvent):void{
var my_url:URLRequest = new URLRequest("http://www.mesmylimbirzus.lt/app222/id.php");
my_url.method = URLRequestMethod.POST;
my_url.data = "kazkas1_t="+kazkas1.text+"&kazkas2_t="+kazkas2.text+"&kazkas3_t="+kazkas3.text;
var my_loader:URLLoader = new URLLoader();
try {
my_loader.load(my_url);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
my php:
<?php
$fp =@ fopen("test.txt", "a");
if($fp){
$current = $_POST['kazkas1_t'] . " " . $_POST['kazkas2_t'] . $_POST['kazkas3_t'] .'\n';
if(@fwrite($current)){
// ok
}else{
// debug issue
}
fclose($fp);
}else{
// answer to flash by something like varNamer=error to tell the flash client that something wrong happen
// or send and email to yourself to debug it
}
?>
Copy link to clipboard
Copied
2 errors:
change
$fp =@ fopen("test.txt", "a");
to
$fp = @fopen("test.txt", "a");
change
if(@fwrite($current)){
to
if(@fwrite($fp,$current)){
and once it works use another path for your text file since everyone can write on it from the internet


-
- 1
- 2