• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

can i delete ALL files in directory ?

Engaged ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

i create a upload test using FileReference & PHP.

In this scenario user upload files to http server.

Now how can i delete all files in /files/uploads folder in AS3

AS3 Code:

req = new URLRequest();

req.url = ( stage.loaderInfo.parameters.f )? stage.loaderInfo.parameters.f : "http://www.website.com/test/upload.php";

uploadFile = new FileReference();

select_btn.addEventListener( MouseEvent.CLICK, browse );

uploadFile.addEventListener( Event.COMPLETE, complete_func );

uploadFile.addEventListener( DataEvent.UPLOAD_COMPLETE_DATA, show_message );

function browse( e:MouseEvent )

{

          filefilters = [new FileFilter('Images',"*.jpg;*.png;*.gif")];

          uploadFile.browse( filefilters );

}

function complete_func( e:Event )

{

          trace( 'complete !' );

}

function show_message(e:DataEvent)

{

if (e.data == 'ok')

          {

          label_txt.text = 'The file has been uploaded.';

          }

else if ( e.data == 'error')

          {

          label_txt.text = 'The file could not be uploaded.';

          }

}

}

PHP Code:

<?php

$uploads_dir = './files/uploads';

if( $_FILES['Filedata']['error'] == 0 ){

          if( move_uploaded_file( $_FILES['Filedata']['tmp_name'], $uploads_dir.$_FILES['Filedata']['name'] ) ){

                    echo 'ok';

                    exit();

          }

}

echo 'error';

exit();

?>

TOPICS
ActionScript

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

You need call another PHP file

<?php

   $directory = './files/uploads';

  

   getDirectoryList ($directory);  

   //This function find all the files in the directory

   function getDirectoryList ($directory)

   {

     // create an array to hold directory list

     $results = array();

     // create a handler for the directory

     $handler = opendir($directory);

     // open directory and walk through the filenames

     while ($file = readdir($handler)) {

       // if file isn't this directory or its parent, add it to the results

       if ($file != "." && $file != "..") {

    //$results[] = $file;

     // Delete Files

    $filename = $file;
 
unlink($filename
); //this delete a file

      }

     }

     // tidy up: close the handler

     closedir($handler);

   }

?>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

how to call this script from flash?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

var request:URLRequest = new URLRequest ("deletFiles.php");

var loader:URLLoader = new URLLoader (request);

//loader.addEventListener(Event.COMPLETE, onComplete);

loader.load(request);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

i tried this but not working....

my code:

var request:URLRequest = new URLRequest ("http://www.site.com/test/deletfiles.php");

var loader:URLLoader = new URLLoader (request);

loader.addEventListener(Event.COMPLETE, onComplete);

loader.load(request);

function onComplete(e:Event):void

{

          trace("Complete");

}

PHP

<?php

   $directory = './files/uploads';

   getDirectoryList ($directory); 

   function getDirectoryList ($directory)

   {

    $filename = $file;

    unlink($filename); //this delete a file

    closedir($handler);

   }

?>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

Change:

<?php

   $directory = './files/uploads';

   getDirectoryList ($directory); 

   function getDirectoryList ($directory)

   {

    $filename = $file;

    unlink($filename); //this delete a file

    closedir($handler);

   }

?>

for this:

<?php

   $directory = './files/uploads';

   getDirectoryList ($directory);  

   function getDirectoryList ($directory)

   {

     $results = array();

     $handler = opendir($directory);

     while ($file = readdir($handler)) {

       if ($file != "." && $file != "..") {

                  $filename = $file;
      
unlink($filename);

      }

     }

     closedir($handler);

   }

?>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

i'm facing same problem. i think problem is in flash loader.

if i enter wrong path flash showing : trace complete.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

LATEST

if Flash trace "complete" this means that the loader is working.

Copy some files to the folder and try testing the PHP script

in a navigator go to:

http://www.site.com/test/deletfiles.php

(where site is your real domain)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines