如何从上传文件夹中删除文件

I am trying to delete a photo from upload folder when i press delete all records are deleted except the picture in upload folder here is my delete, how to i code the snippet to delete from upload folder

//trigger
<?php 
echo '<td><a href="delete.php?staff_id=' . $row['staff_id'] . '"><input type="button" onclick="confirmDelete(event)" value="delete">';

// check if the 'staff_id' variable is set in URL, and check that it is valid
if (isset($_GET['staff_id']) && is_numeric($_GET['staff_id']))
{
    // get staff_id value       
    $staff_id = $_GET['staff_id'];

    // delete the entry
    $result = mysql_query("DELETE FROM development WHERE staff_id=$staff_id") or die(mysql_error()); 
}

In your delete.php script you would need a line like this :

unlink( "path_to_your_upload_directory/".$staff_id.".jpg" );

If you have various file extensions : One way to achieve it is to first save the filename with extension in an appropriate database table when the user/staff uploads the file . Retrieve the same and use it when deleting the file :

$filename_with_extension = 'retrieve this from database table where it is stored';
unlink( "path_to_your_upload_directory/".$filename_with_extension );
if(isset($_GET['staff_id'])&&is_numeric($_GET['staff_id']))
{
    $Staff_Id = mysql_real_escape_string($_GET['staff_id']);
    if($Staff_Id != '.' || $Staff_Id != '..')
    {
        $extension = '.jpg';
        if(unlink('uploads/'.$Staff_Id.$extension))
        {
            $result = mysql_query("DELETE FROM development WHERE staff_id=$staff_id")or die(mysql_error()); 
        }
    }
}

Use unlink function. This will remove a file from the specified directory

unlink() function in PHP. You have to provide full path to that file in parameter.

NOTE: Do not give http:// path.