By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,620 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,620 IT Pros & Developers. It's quick & easy.

Delete a folder...It worked and now it doesn't

100+
P: 142
Hi, Please help here

I made this delete script to delete a folder on the hosting server and the files within.

It worked a month ago but now it does not work...

[PHP]
<?php

$dfolder = $_POST['dfolder'];

$myFile = "$dfolder";
rmdir($myFile);

?>
[/PHP]

It worked on my local server as well but also it aint working on it.

I tried unlink, unset, FTP_delete and the one that is suppose to work rmdir. I even set the permission but the permission are right.

Can some please tell me why it worked and now does not want to work!
Jul 17 '07 #1
Share this Question
Share on Google+
6 Replies


dafodil
100+
P: 392
Hi, Please help here

I made this delete script to delete a folder on the hosting server and the files within.

It worked a month ago but now it does not work...

[PHP]
<?php

$dfolder = $_POST['dfolder'];

$myFile = "$dfolder";
rmdir($myFile);

?>
[/PHP]



It worked on my local server as well but also it aint working on it.

I tried unlink, unset, FTP_delete and the one that is suppose to work rmdir. I even set the permission but the permission are right.

Can some please tell me why it worked and now does not want to work!
Check if you have the existing folder before you delete....
Is there any errors? If yes please show the error....
Jul 17 '07 #2

100+
P: 142
Hi, no it is just a folder with images it it.

The error I get is.

The directory is not empty...It always deleted the files in the folder and then the folder but now I just get that error message.

Regards
Jul 17 '07 #3

epots9
Expert 100+
P: 1,351
give this a try http://us3.php.net/manual/en/function.exec.php

[PHP]
echo exec('rm - r '.$myFile);
[/PHP]
Jul 17 '07 #4

nomad
Expert 100+
P: 664
Hi, Please help here

I made this delete script to delete a folder on the hosting server and the files within.

It worked a month ago but now it does not work...

[PHP]
<?php

$dfolder = $_POST['dfolder'];

$myFile = "$dfolder";
rmdir($myFile);

?>
[/PHP]

It worked on my local server as well but also it aint working on it.

I tried unlink, unset, FTP_delete and the one that is suppose to work rmdir. I even set the permission but the permission are right.

Can some please tell me why it worked and now does not want to work!
webandwe
Two thing you can do.
Make sure you have the right dir. and that the folder is spelled the same as your code.
or
make a new folder and then change your code dfolder to the new folder name.

nomad
Jul 17 '07 #5

mwasif
Expert 100+
P: 801
PHP manual says The directory must be empty. Checkout the manual rmdir().
Jul 17 '07 #6

Motoma
Expert 2.5K+
P: 3,235
This code may help you out:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. /********************************************************************
  3.                                 rm.php
  4. ********************************************************************/
  5. /*
  6.     Deletes a file or directory
  7.     Usage:  rm("filename");
  8.             rm("directory");
  9.             rm("directory/*");
  10.             rm("*.txt");
  11. */
  12. function rm($fileglob)
  13. {
  14.    if (is_string($fileglob))
  15.    {
  16.        if (is_file($fileglob)) return unlink($fileglob);
  17.        else if (is_dir($fileglob))
  18.        {
  19.            $ok = rm("$fileglob/*");
  20.            if (! $ok) return false;
  21.            return rmdir($fileglob);
  22.        } else {
  23.            $matching = glob($fileglob);
  24.            if ($matching === false)
  25.            {
  26.                trigger_error(sprintf('No files match supplied glob %s', $fileglob), E_USER_WARNING);
  27.                return false;
  28.            }
  29.            $rcs = array_map('rm', $matching);
  30.            if (in_array(false, $rcs)) return false;
  31.        }
  32.     }
  33.     else if (is_array($fileglob))
  34.     {
  35.         $rcs = array_map('rm', $fileglob);
  36.         if (in_array(false, $rcs)) return false;
  37.     } else {
  38.         trigger_error('Param #1 must be filename or glob pattern, or array of filenames or glob patterns', E_USER_ERROR);
  39.         return false;
  40.     }
  41.     return true;
  42. }
  43.  
Jul 17 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.