Reputation: 43647
We have a script, /scripts/ourscript.php
and a file, /media/movie1.flv
.
How can we remove this file, when we run ourscript.php
?
Upvotes: 2
Views: 809
Reputation: 39389
Use the unlink
function: http://php.net/manual/en/function.unlink.php
<?php
unlink('/media/movie1.flv');
?>
Upvotes: 0
Reputation: 401002
You need to use the unlink()
function in your ourscript.php
script.
For example :
$success = unlink('/media/movie1.flv');
if ($success === false) {
// TODO : the file has not been deleted ; deal with that problem
}
Note, though, that unkink()
will generate a warning if there's a failure... So, you might want to configure display_errors
properly, or use the @
operator
(Even if using the @
operator is generally not such a good idea)
Upvotes: 2
Reputation: 181280
You need to call unlink("/media/movie1.flv");
Here's DOC on unlink
function. Do keep in mind that the user running your script (usually Apache's user) needs WRITE permissions on the file you are your to delete.
Upvotes: 2