Solved

Calling a Function from a String - error

Posted on 2006-11-25
6
171 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
First name pregmatch 11 30
lastpass auto fill login form 5 24
html input clean up 3 32
two tables one button 11 10
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now