Jump to content

File Permissions


krash11554

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.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/268649-file-permissions/
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
 if(is_file($file))
   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
https://forums.phpfreaks.com/topic/268649-file-permissions/#findComment-1379965
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:

<?php

/**
* 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.
		continue;
	}

	// 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
https://forums.phpfreaks.com/topic/268649-file-permissions/#findComment-1379992
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.