How to make unlink work

This is the PHP code I am using:


<?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(www.recse.org/clergy/documents/Athletic_Center_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 www.recse.org/clergy/documents/Athletic_Center_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?

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

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. :slight_smile: