File Deletion with ActionScript 3.0 and PHP

File Deletion with ActionScript 3.0 and PHP

File Deletion with ActionScript 3.0 and PHP

In a prevouis post I talked about uploading files with ActionScript to a server location.

In this post I wil explain, how server files can be easliy erased from the server from inside ActionScript.

1. The File Delete Script

This is a simple PHP file, that requires a POST variable.

This variable contains the url to the file that needs to be deleted.

Afbeelding 1

2. Calling the script from ActionScript 3.0

I just created a Flex Button, when this button is clicked the function removeFileClicked() is invoked.

private function removeFileClicked():void{
     deleteServerFile("image.jpg");
}

[cc lang="php" width="625" height="500" theme="default"]
private function deleteComplete(e:Event):void{
     Alert.show("Delete Complete");
}

private function deleteServerFile(_url:String):void{
     var proxy:URLLoader = new URLLoader();
     var req:URLRequest=new URLRequest('URL to the deleteFile.php');
     var vars:URLVariables=new URLVariables();
     vars.file = _url;
     req.data=vars;
     req.method= URLRequestMethod.POST;
     proxy.load(req);
     proxy.addEventListener(Event.COMPLETE, deleteComplete);
}

Make sure you have the right permissions on the folders were this PHP script will be active.


About the Author

Daan is a Creative-Geek who loves learning and sharing new techniques! Follow him on Twitter to keep up to date with the Creative-Geeks blog and other subjects. Contact him on e-mail : info[at]creative-geeks.com or visit his webdevelopment company at Webdelight.be