PDA

View Full Version : as3 to php file upload



spazy_t
July 17th, 2009, 11:02 AM
Hello i have been wandering the internet for several days and can't find an answer to my file uploader nightmare, i just want to upload a file from flash via php, i have been using the FileReference class but as soon as i try to upload it nothing happens or at least it tells me its complete in super quick time but nothing has been uploaded and there has been no POST request fired i have checked my directorie paths and they are fine but no joy.

Any help to solve this is hugely appreciated i proper want to get this to work, would be cool to finally get php working with flash for the first time.

below is my code to help see:



import flash.events.*;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.system.Security;

Security.allowDomain("http://127.0.0.1/");

var _uploadUrl:URLRequest;
var _fileName:String;
var _fileRef:FileReference;

_uploadUrl = new URLRequest();
_uploadUrl.url = "http://127.0.0.1/spazy/ftp_v2/build/fileUploader.php";
_fileRef = new FileReference();

upload_btn.buttonMode = true;
browse_btn.buttonMode = true;

//config listeners
_fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
_fileRef.addEventListener(Event.COMPLETE, completeHandler);
_fileRef.addEventListener(Event.SELECT, selectHandler);
_fileRef.addEventListener(IOErrorEvent.IO_ERROR, IOHandler);
browse_btn.addEventListener(MouseEvent.MOUSE_DOWN, browse);
upload_btn.addEventListener(MouseEvent.MOUSE_DOWN, upload);

function progressHandler(e:ProgressEvent):void{
trace("progress");
file_txt.text = "progressHandler: name=" + _fileRef.name + " bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal;
}

function completeHandler(e:Event):void{
//file_txt.text = "complete = "+e;
}

function selectHandler(e:Event):void{
trace("selected");
_fileRef = FileReference(e.target);
file_txt.text = FileReference(e.target).name;
}

function IOHandler(ie:IOErrorEvent):void{
file_txt.text = "IO Error = "+ie;
}

function browse(me:MouseEvent):void{
_fileRef.browse();
}

function upload(me:MouseEvent):void{
trace("upload");
_fileRef.upload(_uploadUrl);
}cheers.

453.0
July 17th, 2009, 12:57 PM
Make sure that the directory to where you are trying to upload files has it's permissions maxed out ( 777 ). If that folder's permissions are not set to 777 then the files you are uploading might not show ( although all the responses from PHP are "ok" ).

spazy_t
July 20th, 2009, 05:27 AM
Thanks very much for your reply but i have re checked just to make sure and yeah all the permissions are maxed out for the directory and still no joy but i dont think it's even getting that far as there is no POST request logged in my firefox firebug when i click my upload button, but i do know its firing the method in flash that holds the upload function.

This thing is proper annoying!

Cheers tho.

Gnoll
July 20th, 2009, 07:17 AM
What about Flash Player's security, do you have a crossdomain.xml?

Gnoll

spazy_t
July 20th, 2009, 07:55 AM
Ah no i dont but that's because the swf and the php file it's accessing is on the same domain so i don't need one for now. Thing is i can see it counting the bytes loaded once i click the upload button but again there is no POST request logged kinda stumpped.

Cheers anyways Gnoll.