Results 1 to 4 of 4

Thread: Delete file from server

  1. #1
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default Delete file from server

    Hello all,
    i have a problem, i cannot delete a file from my server using php. i am using unlink() to delete the file, but its not posting the file name.

    PHP Code:
    <?php
    if($_REQUEST['action']=="del") {
    $con mysql_connect("localhost","root","") or die("sorry");
    mysql_select_db("tblname"$con);
    mysql_query("DELETE FROM db WHERE id={$_REQUEST['id']};");
    // Here is the problem
    $myfile "file:////serverip/test/".$_REQUEST['filename']."";
    unlink($myfile);
    mysql_close($con);
    ?>
    <?php
    //more code
    //the link
    mysql code)
    <
    a onclick=\"return confirm('Are You Sure?');\" href='P&A.php?action=del&id=".$row['id']."&file=".$row['filename']."'>Delete</a>
    Now, the row gets deleted from mysql, but the file doesnt get deleted. it says that "unlink()" isnt working? When i hover over the "delete" button, i see the id and filename, then i guess its not getting passed through that. Please help

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    file:/// the file protocol here means the file is on your computer not on your server.

    To be more precise $myfile = "file:////serverip/test/"

  3. #3
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default

    [file:////serverip] well i use that on a donwload link to download the file from a remote sharedrive. how should i write it then?? i dont think the file name is getting passed through the link.?

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    PHP unlink() can only delete files on the server the script is being run on. If you wanted to delete a file on a remote server, you would need to use PHP's ftp functions.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •