darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 he needs to close the directory before deleting or calling unlink using closedir; Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339326 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 no luck. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339329 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"); } ?> Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339331 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. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339334 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Yeah, there's no GET Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339335 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; Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339337 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. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339339 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>";} ?> Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339342 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 that's mySQL. Mine's flat. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339344 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 you still can use the unlink Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339345 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 but mine has unlink already. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339346 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 Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339347 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Hm. I'll have a go. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339349 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 ); } } } ?> Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339350 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. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339361 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? Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339364 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 yeah. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339365 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? Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339369 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? Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339370 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 Go for it! Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339371 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 :\? Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339372 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'> Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339377 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Sorry, I don't follow. Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339378 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); } } } } ?> Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339386 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? Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/page/4/#findComment-339396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.