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.
2. Calling the script from ActionScript 3.0
I just created a Flex Button, when this button is clicked the function removeFileClicked() is invoked.
[code lang="actionscript"]
private function removeFileClicked():void{
deleteServerFile("image.jpg");
}
[/code]
[code lang="actionscript"]
private function deleteComplete(e:Event):void{
Alert.show("Delete Complete");
}[/code]
[code lang="actionscript"]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);
}[/code]
Make sure you have the right permissions on the folders were this PHP script will be active.