deleting file using unlink

Discussion in 'PHP' started by cris02, Oct 20, 2006.

  1. #1
    Hello..

    Well i try to delete a files using unlink but returns me an error "Permission Denied". i'll try to set the directory to chmod 777 but still the same error. here's my code:
    
    <?php
    //==== del.php ====
    
    $filepath = $fle;
    if ($_REQUEST['loc']=="newjob") { 
    $linkval="newjob.php"; 
    }
    if (! unlink ($filepath)) {
       echo ("Couldn't delete file");
    } else {
       header("Location: $linkval");
    }
    ?>
    
    Code (markup):
    and then for the link delete
    
    <A HREF='del.php?fle=$destination$file&loc=newjob'>Delete</A>
    
    Code (markup):
    thanks
     
    cris02, Oct 20, 2006 IP
  2. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try to set the directory, file you wan't do delete to 777.
     
    Morishani, Oct 21, 2006 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    If the file is chmoded to 777 you should be able to remove it.

    Also check that GUID and UID are set to apache

    Peace,
     
    Barti1987, Oct 21, 2006 IP
  4. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    wow...are you sure you want to have that code out in the wild? I hope that is in a protected area.

    Bobby
     
    Chemo, Oct 21, 2006 IP
  5. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I agree with Chemo. As convenient as that bit of code is, I would stick to deleting files from an ssh client session or from a site management panel, such as webmin, directadmin, cpanel, or . . .

    In my programs I allow files to be created, erased, modified. But I never allow the choice of files to be defined by a URL string because people could simply edit the URL to erase any file of their choosing.
     
    clancey, Oct 21, 2006 IP