Link to home
Start Free TrialLog in
Avatar of Cyber-Drugs
Cyber-DrugsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Calling a Function from a String - error

Hi guys,

I have this:

$param = "../foldera/folderb";
delete_recursive_dirs($param);


delete_recursive_dirs() - is a function which deletes a folder and all it's contents.


When I run the code above, it throws an error, but when I run it like this:

delete_recursive_dirs("../foldera/folderb");


it works perfectly...



Any ideas on what I need to do for this to work?


Cheers!
Avatar of Roonaan
Roonaan
Flag of Netherlands image

The code as you have posted it now should work perfectly fine.

-r-
Avatar of Cyber-Drugs

ASKER

Unfortunately, it doesn't...

Anything I can try?
Using echo to display debug data.

echo '<div>'.$params.'</div>';

And possibly edit delete_recursive_dir to show debug data as well.

-r-
Tried that, doesn't work,

URL I call:

mypage.php?function=cb_deletecase&param='../Development/OwcClientFiles/19/1/1/61/358'


and here's my code if it helps?

<html>
      <head>
<?php
      function delete_recursive_dirs($dirname)
      {
            // recursive function to delete
        // all subdirectories and contents:
        if(is_dir($dirname))$dir_handle=opendir($dirname);
        while($file=readdir($dir_handle))
        {
          if($file!="." && $file!="..")
          {
            if(!is_dir($dirname.DIRECTORY_SEPARATOR.$file))
                  unlink ($dirname.DIRECTORY_SEPARATOR.$file);
            else delete_recursive_dirs($dirname.DIRECTORY_SEPARATOR.$file);
          }
        }
        closedir($dir_handle);
        rmdir($dirname);
        return true;
      }      
      
      $function = $_GET['function'];
      $param = stripslashes($_GET['param']);
      if ($function != "") {
            $background = 'orange';
      } else {
            $background = 'green';
      }
      
      switch($function) {
            case "cb_deletecase":
                  $background = 'blue';
                  $url = delete_recursive_dirs($param);
                  break;
      }
?>
      </head>
      <body bgcolor='<?php echo $background; ?>'>
            <?php
                  echo "delete_recursive_dirs(".$param.")\n";
                  echo "\t".$_SERVER['SCRIPT_NAME']."\n";
                  echo "\t".$url."\n";
            ?>
      </body>
</html>




and this is the full error:


<html>
      <head>
<br />
<b>Warning</b>:  readdir(): supplied argument is not a valid Directory resource in <b>C:\Program Files\xampp\htdocs\Development\FuncCall.php</b> on line <b>9</b><br />
<br />
<b>Warning</b>:  closedir(): supplied argument is not a valid Directory resource in <b>C:\Program Files\xampp\htdocs\Development\FuncCall.php</b> on line <b>18</b><br />
<br />
<b>Warning</b>:  rmdir('../Development/OwcClientFiles/19/1/1/61/358') [<a href='function.rmdir'>function.rmdir</a>]: No such file or directory in <b>C:\Program Files\xampp\htdocs\Development\FuncCall.php</b> on line <b>19</b><br />
      </head>
      <body bgcolor='blue'>
            delete_recursive_dirs('../Development/OwcClientFiles/19/1/1/61/358')
      /Development/FuncCall.php
      1
      </body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DOH!!!

Works perfectly now, cheers Roonaan! :)