How to delete a file by using PHP

Due to some reason I uploaded a plugin called “wpaudio-mp3-player.2.1.0.zip”, which is a light weight mp3 player, to the wordpress /uploads directory. Looks like my web server do not like the word mp3 anywhere in my file name (you have to pay to get around it). so even though I was able to upload it by a program, I can not just delete it by using a command in my FTP client. The only way I can remove this file is to use PHP unlink function.

<?php
$myFile = "wpaudio-mp3-player.2.1.0.zip";
unlink($myFile);
?>

Save this to a php file and upload it to the same directory that I want the file to be deleted. then run this php, I’m done. Apparently php uses similar syntax to the Unix C unlink() function. Everyone thinks there should be a delete command, php.net even has a delete dummy entry only point to the unlink command.

Leave a Reply

Your email address will not be published. Required fields are marked *