Jump to content

Newbie - Unlink question


unkempt

Recommended Posts

Ok so i am using flash with php

 

the following works well if the unlink.php (below) resides in the "temporary" folder :

 

In flash:

[pre]path = "http://localhost/temporary/unlink.php?";

var file:String = "barth_t8.jpg";

 

del = new LoadVars();

del.delstr = file;

del.sendAndLoad(path, del, "POST");

 

del.onLoad = function(){

tracer = "file removed - "+this.removed;

}[/pre]

 

In PHP:

[pre]<?php

$myFile=$_POST[delstr];

unlink($myFile);

print "&removed=".$myFile;

?>[pre][/pre][/pre]

 

 

So.... if i was to make my path - "http://localhost/unlink.php?";  (i.e. no temporary folder)

how could i change this so flash tells the php which folder the file resides in and then delete it?

 

Any help would be appreciated

Link to comment
https://forums.phpfreaks.com/topic/98035-newbie-unlink-question/
Share on other sites

To provide the directory over the url, it'll need to be like this:

 

http://yoursiter.com/unlink.php?dir=path/to/file

 

Then in php you'd do:

if(isset($_GET['dir']) && isset($_POST['delstr']))
{
    $dir_path  = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['dir'];
    $file_path = $dir_path . '/' . $_POST['delstr'];

    if(is_dir($dir_path) && file_exists($file_path))
    {
        unlink($file_path);
    }
    else
    {
        'ERROR: File (' . $file_path . ') does not exist!';
    }
}
else
{
    die('Invalid data!');
}

Looking at the Flash manual for the sendAndLoad function Flash can receive data from the page.

 

Change the following in the in unlink.php:

if(is_dir($dir_path) && file_exists($file_path))
    {
        unlink($file_path);
    }

 

to:

if(is_dir($dir_path) && file_exists($file_path))
    {
        unlink($file_path);

        echo '&deleted=OK&';
    }

 

Then in your flash change this:

del.onLoad = function(){
tracer = "file removed - "+this.removed;
}

to:

del.onLoad = function() {
   if(this.deleted== 'OK')
   {
      tracer = "file removed';
   }
}

 

Thankyou very very much - you have made my life a lot easier than the workarounds i had in mind.

 

Could you recommend any good starter books - i am fairly ok with actionscript but this php is doing my head in

I'm a complete novice at Flash and actionscript - rarely use it. PHP is a programming language, like all programming languages it takes time to grasp.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.