LemonInflux Posted August 31, 2007 Share Posted August 31, 2007 You probably know by now, I'm setting up an image uploader for a project, and want to add user interfaces. Well, everything's ok now, apart from delete. With help, I've come upon this code: <?php $files = array(); $dir=opendir($f_user); while(($file = readdir($dir)) !== false) { if($file !== '.' && $file !== '..' && !is_dir($file)) { $files[] = $file; } } closedir($dir); natcasesort($files); echo "<ul>\n"; for($i=0; $i<count($files); $i++) { if($files[$i] != "index.php") echo "<li><a href=\"$dir/".$files[$i]."\">".$files[$i]."</a> - <a href=\"delete.php?del=$files[$i]\">Delete</a></li>\n"; } echo "</ul>\n"; ?> This code lists the directory contents and adds a 'delete' option next to the file. Upon pressing delete, it will send you to http://reflexprojects.net/rs/upload/delete.php?del=yourfile.whatever In delete.php, I have <?php $file = $_GET['del']; $dir = "$f_user/$file" if(unlink($dir)) { echo "The file was deleted successfully."; } else { echo "There was an error trying to delete the file."; } ?> Basically, this gets the file and tries to delete it. However, on this screen, I get nothing, just a blank white page. Not even the error echo works. So, here's my question: What's wrong with the second script? If you would like to see what happens, log in at http://reflexprojects.net/rs/upload/secure_page.php?, with username and password as 'test'. Upload a picture, then try to delete it. Thanks in advance, Tom. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/ Share on other sites More sharing options...
phpSensei Posted August 31, 2007 Share Posted August 31, 2007 why is this empty? $files[] = $file; Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-338900 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 Should it have anything in? Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-338901 Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 I would think it is supposed to be empty. I think the unlink function might be causing some kind of problem. What if you do "echo $dir" right before the unlink line? See if something gets displayed, if not, comment out that entire if statement and see what it prints out for the $dir, it might be something weird. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-338909 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 It doesn't echo anything, still blank page :\ Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-338911 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 Are u sure u have a directory like: $dir = "$f_user/$file"? Normally if smth goes wrong an error should be printed, but maybe u have error_reporting off. If u have access to php.ini or a custom one try chaning error_reporting = e_all to see if u get any error. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-338925 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Morning bump. Yes, I'm sure I do. That's where the images are stored. I'll check errors. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339171 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 No errors even show. It's just completely blank. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339174 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 I'm fairly sure it's the GET thing. There isn't much else that could be causing it.. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339189 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 did you try replacing $_GET with $_REQUEST ? Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339190 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 No, but I just tried it, and no luck :\ Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339192 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 ty doing a query and selecting it that way? Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339195 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 erm...Was that 'thank' 'you doing a query and selecting it that way?' or 'thank you' 'doing a query and selecting it that way? And read the code, I'm not sure there's another way of displaying the directory contents in a list in another way. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339198 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 oops sorry my keyboard is being weird anyway i was trying to say do a mysql_query to select the delete field and grab it that way. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339199 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 There's no MySQL involved. This was a test to see if I could do it without MySQL. I'm sure I can, if I just work this bit out. Everything else has been fine.. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339200 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 <?php (!isset($_GET['del'])){ echo "Could not Delete the file!"; } else { $file = $_GET['del']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339205 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Yet again, the all to friendly 'blank screen' shows. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339207 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 <?php if (!isset($_GET['del'])){ echo "Could not Delete the file!"; } else { $file = $_GET['del']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339208 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Blank.. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339210 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 not sure if thi will help but i got this from php.net when i looked up opendir delete <?php 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); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339214 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Uuuh...That just emptied the folder. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339215 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 Wait, no it didn't, it just didn't list anything. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339216 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 weird so it didnt work at all? Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339218 Share on other sites More sharing options...
LemonInflux Posted September 1, 2007 Author Share Posted September 1, 2007 nope. Just, blank. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339219 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 oops try adding $dir = "/path/to/base/dir"; appearantly i left that line out so it wouldnt read the directory path and wouldnt do anything. Quote Link to comment https://forums.phpfreaks.com/topic/67496-_get-from-a-url/#findComment-339220 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.