SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to make unlink work

    This is the PHP code I am using:
    PHP Code:
    <?php
    // file name is delete.php
    include($_SERVER['DOCUMENT_ROOT']."/clergy/includes/initialize.php");

    var_dump($_POST);
    echo 
    '<br /><p>The above is a dump of all variables in POST.</p>';

     if (isset(
    $_POST['submitted'])) { // Handle the form.
        
    $filenm $_POST['filenm'];
        echo 
    'the file to delete is:' $filenm ;
        
    $filenm mysql_real_escape_string (trim($filenm));

     }

     if(isset(
    $_POST['filenm']))
            {
                
    $folder 'www.recse.org/clergy/documents/';
                            
    unlink($folder.$filenm);
                echo 
    "The file: ".$filenm." has been deleted.";
            } else {
                            echo 
    "No files were deleted.";
                    }
                    echo 
    '<a href="delete_files.html">Return to file deletion selection page.</a><br /> <a href="/clergy/">Return to Clergy main page.</a>';
                    
    echo 
    '<br /><p>second attempt</p><br />';


        
    $fileToDel $folder $filenm;
            
    chdir('../documents/');
        
    $do unlink($fileToDel);
        if(
    $do=="1"){
            echo 
    "The file was deleted successfully.";
        } else { echo 
    "There was an error trying to delete the file."; }
    ?>
    This page gives me an error of:
    Warning: unlink(http://www.recse.org/clergy/document..._data_room.pdf) [function.unlink]: No such file or directory in /homepages/4/d322583329/htdocs/diocese/clergy/documents/delete.php on line 18

    If I copy http://www.recse.org/clergy/document..._data_room.pdf and paste into my web browser, I will load the pdf file.

    I actually get this error twice. Once on line 18 when I try one method of deleting the file, and a second time on line 30 when I try a different line of code.

    What am I doing wrong?
    Each day is a learning experience.

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    The path that you give to unlink() must be the path on the server's filesystem, not the URL of the file. In other words, something like /homepages/4/d322583329/htdocs/diocese/clergy/documents/Athletic_Center__data_room.pdf
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well this is a first for me. I have never had to use the server information, but it did the trick.

    THANK YOU!

    Now I can finish this off an make it pretty.
    Each day is a learning experience.


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
  •