Skip navigation
Currently Being Moderated

can i delete ALL files in directory ?

May 23, 2012 6:44 AM

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();
?>
 
Replies
  • Currently Being Moderated
    May 23, 2012 7:52 AM   in reply to Venkom

    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);

     

       }

     

    ?>

     
    |
    Mark as:
  • Currently Being Moderated
    May 23, 2012 9:44 AM   in reply to Venkom

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

     

    var loader:URLLoader = new URLLoader (request);

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

    loader.load(request);

     
    |
    Mark as:
  • Currently Being Moderated
    May 23, 2012 11:20 AM   in reply to Venkom

    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);

     

       }

    ?>

     
    |
    Mark as:
  • Currently Being Moderated
    May 23, 2012 1:07 PM   in reply to Venkom

    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)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points