Jump to content

Recommended Posts

Hi Everyone

 

Is there a function to delete a folder and its content by just saying you want to delete the folder?

 

I currently I know how to do it by deleteing every file with unlink and then deleting the folder with rmdir. I  was just wondering if there was well a less pain in the arse way.

 

its for deleting a photo album folder

Link to comment
https://forums.phpfreaks.com/topic/138562-deleting-a-full-folder-dir/
Share on other sites

I'm 99.99% sure that you have to delete each file individually, then delete the folder when it's empty. However, depending on your system setup, you might be able to get away with some server commands. Example:

<?php
$pathto = '/home/user/public_html/images/iwanttodeletethis/';
system ("rm -Rf $pathto") ;
?>

That should delete the folder and all the contents, given your running the correct os :P

hmmm im not to sure if itll delete the files as well but you could try:

<?php
rmdir("path/folder_name");
?>

hope this helps.

 

EDIT: im sorry this is of no use to you, i re-read your post. my mistake

if a mod is around hopefully they could delete this post?

No sadly the folder has to be empty first...below is currently the code I have which deletes it all.

 

I was just hoping that there might have been a function out there that would have done the same thing just would have mess around deleting all the files from the folder first

 

  	$getpic = "SELECT *
	  FROM movieimages
	  WHERE movie_id = $mid";
$result = mysql_query($getpic)
  or die(mysql_error());
	while ($row = mysql_fetch_array($result)) {

	$DelImage ="images/" . $mid . "/" . $row ['image_id'] . ".jpg";

	$DelThumb = "images/" . $mid . "/thumbs/" . $row ['image_id'] . ".jpg";
	$dirImage = "images/" . $mid;
	$dirThumb = "images/" . $mid . "/thumbs";

	unlink($DelImage);
	unlink($DelThumb);
}	

rmdir($dirThumb);
rmdir($dirImage);

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.