SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict ARSA's Avatar
    Join Date
    Apr 2003
    Location
    San Juan, Puerto Rico
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delete items in a folder ???

    Ok, I want to erase all the files inside 2 folders at the same time... how do i do this...

    the path to the folders are:

    http://www.bsinternationalstock.com/images/spic/

    http://www.bsinternationalstock.com/images/lpic/

    This is the delete inventory code im using...
    PHP Code:
    <?php 
    ####################################################################
    ## Erase the Whole Inventory at once ###############################
    ####################################################################

        
    echo ("Make Sure You Know what you're doing");
    if (
    $_POST['trash'] == "Trash It"
       { 
        
    $sql 'TRUNCATE TABLE `Inventory_A` ';
                   
        if (@
    mysql_query($sql)) 
           { 
            echo( 
    "<br><b>The complete Inventory_A has been ERASED.</b>"); 
           } 
            else 
           { 
            echo( 
    "<br>You Can't delete the inventory.<br><br> " 
            
    mysql_error() . " "); 
          }  
    }
       
    ?>
    Thanxs
    "I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world." - Albert Einstein

  2. #2
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unlink() will do it, so you'll need to loop through the directory using readdir() and unlink() every file within it. (Make sure to check that it is a file and not a folder, (which will also exclude . and ..))
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  3. #3
    SitePoint Addict ARSA's Avatar
    Join Date
    Apr 2003
    Location
    San Juan, Puerto Rico
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was trying to do something like this...
    PHP Code:
        $query1mysql_query("SELECT spic_path FROM `Inventory_A`" );
        
    $file mysql_result($query100);
        
    unlink($file);

        
    $query2mysql_query("SELECT lpic_path FROM `Inventory_A` ");
        
    $file mysql_result($query200);
        
    unlink($file); 
    Can you help me do it your way?
    "I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world." - Albert Einstein

  4. #4
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure, here it goes [img]images/smilies/wink.gif[/img]
    PHP Code:
    $dir opendir('./images/spic/');
    while (
    false !== ($file readdir($dir)))
    {
        if (
    filetype($file)=='file')
            
    unlink($file)
    }
    closedir($dir); 
    My bad, updated it.
    Last edited by cyborg from dh; May 16, 2003 at 13:42.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  5. #5
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Donīt forget to Close the directory ...

    otherwise check the manual
    http://www.php.net/manual/en/ref.filesystem.php
    http://www.php.net/manual/en/ref.dir.php
    the neigbours (free) WIFI makes it just a little more fun


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
  •