Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Calling a Function from a String - error

Posted on 2006-11-25
6
178 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 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