| |
|
PHP File delete using unlink function |
We can delete files by giving its URL or path in PHP by using unlink command. This command will work only if write permission is given to the folder or file. Without this the delete command will fail. Here is the command to delete the file.
unlink($path);
Here $path is the relative path of the file calculated from the script execution. Here is an example of deleting file by using relative path
$path="images/all11.css";
if(unlink($path)) echo "Deleted file ";
We have used if condition to check whether the file delete command is successful or not. But the command below will not work.
$path="http://domainname/file/red.jpg";
if(unlink($path)) echo "Deleted file ";
The warning message will say unlink() [function.unlink]: HTTP does not allow unlinking
| |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|
|
|