SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Removing files using bash commands in PHP Script

    Hi all

    I am trying to find a way to remove files that have been stored on my server through my PHP script.

    I am able to use the list successfully but the removal of the files is not working.

    For testing purposes I created a small PHP script to test the Bash command execution. The code I used is as follows:

    PHP Code:
    <?php
    $name
    ="sheep";

    echo 
    exec('ls /var/www/'.escapeshellarg($name).'/kind*');


    ?>
    This works perfectly and returns:
    /var/www/sheep/kindsofsheep

    If I replace the 'ls' with 'rm' (or any derivative thereof) absolutely nothing happens.
    I have also tried using the 'system' command.

    Can anyone suggest a way of removing the files?

    Thanks

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Can you not just iterate through a list of the files present and use unlink?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use -v to get verbose output, it might provide an idea what's wrong. My guess is you don't have permissions.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there

    I think it's a permission issue. I have changed the permissions on the files that I'm trying to delete and on the PHP script and none of that is working. Anyone have any ideas as to what the permissions should be? I have set them to RWXR-XR-X (755) and to RWXRWXRWX (777). I even changed the ownership on the files.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also tried unlink as well as creating a bash script to do the removal.
    The script works if I run it manually but not if I call it in PHP


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
  •