Solved

Calling a Function from a String - error

Posted on 2006-11-25
6
176 Views
Last Modified: 2013-12-12
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!
0
Comment
Question by:Cyber-Drugs
  • 3
  • 3
6 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 18013036
The code as you have posted it now should work perfectly fine.

-r-
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18013047
Unfortunately, it doesn't...

Anything I can try?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 18013059
Using echo to display debug data.

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

And possibly edit delete_recursive_dir to show debug data as well.

-r-
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18013086
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>
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 18013098
Shouldn't
mypage.php?function=cb_deletecase&param='../Development/OwcClientFiles/19/1/1/61/358'
be
mypage.php?function=cb_deletecase&param=../Development/OwcClientFiles/19/1/1/61/358

-r-
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18013120
DOH!!!

Works perfectly now, cheers Roonaan! :)
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question