Wednesday, October 29, 2008

How to delete a file using PHP ?

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

Article Source

0 comments:

Your Ad Here
Reader's kind attention....The articles contained in this blog can be taken from other web sites, as the main intention of this blog is to let people get all sides of the web technologies under the single roof..so if any one finds duplication or copy of your articles in this blog and if you want that to be removed from this ..kindly inform me and i will remove it...alternatively if you want me to link back to your site with the article...that can also be done...

Thanks,
Webnology Blog Administrator
 

blogger templates