PHP – How to delete a File

This post shows you how to delete a file using PHP. To do this, we simply use unlink() function which lets us delete a file. This function returns TRUE on success or FALSE on failure.

example.php
function deleteFile($filePath)
{
    if (is_file($filePath)) {
        return @unlink($filePath);
    }
}

Use the function:

deleteFile('filename.txt');
0 0 vote
Article Rating
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x