Jump to content

File Permissions


Recommended Posts

I have had this same problem when i started to make to directorys with mdir function. now i am having problems when i use the unlink function. heres the code.

unlink('uploads/cars/' . $user_id . '/car' . $car_number . '/');
unlink('uploads/cars/' . $user_id . '/thumbs/car' . $car_number . '/');

I am getting back

Warning: rmdir(uploads/cars/15/car1/) [function.rmdir]: Directory not empty inC:\inetpub\wwwroot\garage\phpfunctions\functions.php on line 315


Warning: unlink(uploads/cars/15/thumbs/car1/) [function.unlink]: Permission denied inC:\inetpub\wwwroot\garage\phpfunctions\functions.php on line 317


I have already set all permissions to the root directory idk what else to do. By the way im on IIS.


Link to comment
Share on other sites

<?php // Removing a directory & all its content
// glob('DIR/PATH/{,.}*', GLOB_BRACE); -- GLOB_BRACE will remove any hidden files in the directory.
$files = glob('DIR_NAME/{,.}*', GLOB_BRACE);
foreach($files as $file){ // Loop through each file in the DIR
   unlink($file); // Removing the file from the DIR
//If you don't want to remove the folder then remove the line below this comment.
rmdir('DIR_NAME'); // Remove the DIR


I hope this is helpful.

Link to comment
Share on other sites

Actually, in this case you'll want something that recursively deletes files and folders, in case the folders contain other folders. That's why I recommend using the following function:


* Will remove a file, or a folder and all of its contents.
* @param string $target Target folder/file to delete.
* @return bool
function unlink_recursive ($target) {
// If target is a file, just unlink it straight away.
if (is_file ($target)) {
	return unlink ($target);

// Target is a folder, so get all of its elements.
$contents = scandir ($target);

// Strip the meta-folder records.
array_shift ($contents);
array_shift ($contents);

// Loop through the individual records.
foreach ($contents as $file) {
	// Build the correct path to the file record.
	$file = $target.'/'.$file;

	// If record is a folder, recursively delete it and its contents.
	if (is_dir ($file)) {
		// In case of error, stop executing deletions.
		if (!unlink_recursive ($file)) {
			return false;

		// Skip to the next record.

	// Record is a file, delete it.
	if (!unlink ($file)) {
		// In case of error, stop executing deletions.
		return false;

// Finally, remove the folder itself.
if (!rmdir ($target)) {
	// In case of error, stop executing deletions.
	return false;

// Return successfully.
return true;


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.

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.