darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 he needs to close the directory before deleting or calling unlink using closedir; Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 no luck. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 <?php $dir=opendir($f_user); while(($file = readdir($dir)) !== false) { if($file !== '.' && $file !== '..' && !is_dir($file)) { $files[] = $file; } } closedir($dir); if (!unlink($file))  {  echo ("Error deleting $file");  } else  {  echo ("Deleted $file");  } ?>  Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 just 'error deleting' this time. So the file path is wrong I think. Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Yeah, there's no GET Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 <?php $file = $_GET['del']; $dir = ($f_user); recursive_delete($dir); function recursive_delete( $dir ) {     if (is_dir($dir)) {      if ($dh = opendir($dir)) {        while (($file = readdir($dh)) !== false ) {             if( $file != "." && $file != ".." )             {                 if( is_dir( $dir . $file ) )                 {                     echo "Entering Directory: $dir$file<br/>";                     recursive_delete( $dir . $file . "/" );                     echo "Removing Directory: $dir$file<br/><br/>";                     rmdir( $dir . $file );                 }                 else                 {                     echo "Deleting file: $dir$file<br/>";                     unlink( $dir . $file );                 }             }        }        closedir($dh);      }     } } ?>   Try putting  else                 {                     echo "Deleting file: $dir$file<br/>";                     unlink( $dir . $file );                 }   after closedir; Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 same story. Deletes everything, not just 1 file. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 my full code for my gallery worth a shot to modify it for urs  <?php if($row['user'] == $_SESSION['username']){       $query = "DELETE FROM `gallery` WHERE `id`='$id'";       $result = mysql_query($query);       unlink("images/user/image/" . $file);       echo "<center><b>Image Deleted</b></center>";} ?> Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 that's mySQL. Mine's flat. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 you still can use the unlink Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 but mine has unlink already. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 i know but this one specifies the exact path to the folder where you want to delete stuff Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Hm. I'll have a go. Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 my code now:  <?php $file = $_GET['del']; $dir = ($f_user); recursive_delete($dir); function recursive_delete( $dir ) {     if (is_dir($dir)) {      if ($dh = opendir($dir)) {        while (($file = readdir($dh)) !== false ) {             if( $file != "." && $file != ".." )             {                 if( is_dir( $dir . $file ) )                 {                     echo "Entering Directory: $dir/$file<br/>";                     recursive_delete( $dir . "/" . $file);                 }                 else                 {                     echo "Deleting file: $dir/$file<br/>";                     unlink( $dir . "/" . $file );                 }             }        }        closedir($dh);      } else                 {                     echo "Deleting file: $dir/$file<br/>";                     unlink( $dir . "/" . $file );                 }     } } ?> Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Hm, is it just me, or was this board offline for like, a day? Anyways, bumped. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 it deletes everything right and you want files deleted one at a time? Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 yeah. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 just abit of advice but instead of a link have a radio button and if that radio button is selected or bubbled then it will delete that image? Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 oo, that'd be even better. But can we make it a checkbox? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 Go for it! Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 so uhh...If we can't get this working, how do I make the checkbox work :\? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 <?php while (list ($key,$val) = @each ($box)) { echo "$val,"; } ?> <input type=checkbox name=box[] value='delete'> Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Sorry, I don't follow. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 that just makes sure the box is checked the following code will make sure if each check box is posted that it will follow out on function recursive delete.   <?php            foreach($_POST['del'] as $delete) { function recursive_delete( $dir ) {     if (is_dir($dir)) {      if ($dh = opendir($dir)) {        while (($file = readdir($dh)) !== false ) {             if( $file != "." && $file != ".." )             {                 if( is_dir( $dir . $file ) )                 {                     echo "Entering Directory: $dir$file<br/>";                     recursive_delete( $dir . $file . "/" );                     echo "Removing Directory: $dir$file<br/><br/>";                     rmdir( $dir . $file );                 }                 else                 {                     echo "Deleting file: $dir$file<br/>";                     unlink( $dir . $file );                 }             }        }        closedir($dh);      }     } } }   ?> Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Sorry, that's the code for the delete.php, right? What do I put in the upload page? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.