Solved

Calling a Function from a String - error

Posted on 2006-11-25
6
180 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
[X]
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
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

726 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