Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: PHP - Deleting variable and file together

  1. #11
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You can't delete the containing folder but why not a parallel file like:
    dir/subdir2/example.php from dir/subdir1/del.php-- path: ../subdir2/example.php
    similar to dir/ex2.php using ../ex2.php

    I have never had the need to try it though. You could easily do it with an include, regardless.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #12
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't understand... But say this is your root folder layout:


    Within includes/unlinkthis.php, you could not do:
    PHP Code:
    unlink("../examples/file.php"); 
    Last edited by Nile; 01-12-2010 at 10:48 PM.
    Jeremy | jfein.net

  3. #13
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    can someone show me how to create form where you can choose in RADIO style.
    Also it has two buttons and one value to send - ID.
    One button deletes existing file, other renames it to good.png

    but everythin in one form. Also some php before header I think thanks

  4. #14
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    PHP Code:
    <?php
    function get_files(){
      
    $files glob("*");
      
    $radio = array();
      foreach(
    $files as $key => $value){
        if(
    is_dir($files[$key])){
          unset(
    $files[$key]);
          continue; 
    //thanks to techietim
        
    }
        
    $radio[] = '<input type="radio" name="delete" id="'.$key.'" value="'.$value.'" /><label for="'.$key.'">'.$value.'</label><br />';
      }
      return 
    implode($radio);
    }
    if(isset(
    $_POST['submit'])){
      
    unlink($_POST['delete']);
    }
    if(isset(
    $_POST['rename'])){
      
    rename($_POST['delete'], "good.png");
    }
    ?>
    <form action="" method="post">
    <?php
    echo get_files();
    ?>
    <input type="submit" name="submit" value="Submit"/>
    <input type="submit" name="rename" value="Rename"/>
    </form>
    Last edited by Nile; 01-17-2010 at 05:26 PM.
    Jeremy | jfein.net

  5. #15
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    ok, looks great... Can you explain how it works? I dont understand the function thing... (also, why you use global?)

  6. #16
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    It's glob(). It gets all the files in the directory.

    The first function of the code gets all the files, and displays them in radios.

    And the next part renames/unlinks.
    Jeremy | jfein.net

  7. #17
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    How'd it work out for you?
    Jeremy | jfein.net

  8. #18
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    I am really sorry Nile, that I haven't seen your last posts... I was working on something else...

    So, it works great

    But one more question. I have mysql information of file:

    $name
    $directory
    $username - who uploaded.

    How I can let to see only those files to owners, which only they uploaded.
    I don't want that everyone could delete all files...

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
  •