SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Delete Directory Using PHP FTP Functions?

    Hello,

    I'm trying to delete a directory.

    I've tried rmdir, but that doesn't work because of a permissions problem (even when I have the permissions at 777.)

    So I'm trying to use the FTP functions. I've got them working for everything else, but I don't seem to be able to get them to delete a directory.

    I've tried:
    ftp_delete($conn_id, 'directory');

    But it doesn't work, regardless of whether there is anything in the directory or not.

    Any ideas?

    Thanks.

  2. #2
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you use rmdir, what errors do you get? What code do you use?
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    rmdir('emptydir');

    Error:
    Warning: rmdir(emptydir) [function.rmdir]: Permission denied in /home/affiliat/public_html/test.php on line 12

    Permissions:
    0777

  4. #4
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to just remove the file "test.php", you don't need rmdir. Try this:

    PHP Code:
    unlink("test.php"); 
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  5. #5
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, test.php is the file that is being run. 'emptydir' is the directory that it's trying to delete. Both of which are placed in the public_html directory.

  6. #6
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is php in safe mode?

  7. #7
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No idea. How do I check?

  8. #8
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    phpinfo()

  9. #9
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but safe mode is off.

    Any other ideas?

  10. #10
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if the script is running on a different server than the directory is located on, your gonna need to use ftp_rmdir()

  11. #11
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another thing to check::i believe that it's not only the permissions of the directory you're trying to delete that you have to worry about, but all the dirs above that one. so this particular directory might be 0777, but if a ../../../ directory is read only, you won't be able to delete.

  12. #12
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's on the same server. They're located at:

    public_html/test.php (this does the deleting)
    public_html/emptydir (to be deleted, has nothing in it)

    And the permissions are all 777.

    So it doesn't quite make sense.

    But I'll try ftp_rmdir anyway and see if that works.

  13. #13
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whats the permissons of public_html/ ?

  14. #14
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    public_html is at 0755.

  15. #15
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    think you need write access to delete something within a directory.
    emptydir is in the public_html directory

  16. #16
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah-ha! That fixed it.

    Thanks a lot!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •