PHP to Programatically delete a file

I am writing a plugin that allows the user to upload files to the upload directory of WordPress.

I want them to be able to “uninstall” the files with the click of a button. When the user clicks the button, I want the files to be deleted. I have successful been able to set up uploading and placing the files in the correct directory, but when it comes to deleting the files it is not working.

Read More

I am trying a very simple unlink('file/path'); but it doesn’t seem to be deleting my file.

<?php

$filename = 'direct/path/to/file/for/testing/purposes';
unlink($filename);

?>

It seems like the function is running when I click the button, but the file is never deleted. The path is correct as I’ve double checked it a few times. Is there something I am doing wrong?

Related posts

1 comment

Comments are closed.