Jump to content

[SOLVED] Permission denied for unlink() on directory


bassguru

Recommended Posts

Hello everyone

 

I am attempting to delete a folder on my WAMP computer using unlink(). The problem is that I recieve the following error when I run the script:

 

Warning: unlink(...) [function.unlink]: Permission denied in C:\wamp\www\...php

 

Here is the code:

 

	if ($file) {
	$deleteFile = $file;
	unlink("images/display/".$deleteFile);
}

 

I doubt there is a problem with the code.

 

 

How do I sort the permission for the Apache? When the folders are created they are given a permission of 0777 so it should be OK?

 

Perhaps its just Windows =[

 

Many thanks in advance

bassguru

Link to comment
Share on other sites

Setting permissions to 0777 has no effect on a windows platform

 

I would say change the files permissions to everyone, and re-try the script, but if you created the file via a php script it should be fine..

 

try rebooting windows then try a simple 1 line script to delete the file, if that works. then I would guess you have one of the following problems

1. the file has been opened and not closed.

2. the $file is empty and PHP is attempting to unlink a folder

3. you have some special permission set to stop the deleting process

Link to comment
Share on other sites

Sorry for wasting everyone's time!

 

I was attempting to delete a folder with unlink() (which is a function for file deletion, not folder deletion).

 

I am now using rmdir(), which works perfectly.

 

The only problem is when there are files inside the folder (rmdir cannot delete directories when there are files stored within them) I am deleting, in which case I have a script that deletes all the files inside the folder before it deletes the actual folder itself.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.