LemonInflux Posted August 31, 2007 Share Posted August 31, 2007 I have built an image uploader, but with logins etc. etc. for people to have their own areas. However, it suddenly dawned on me, there is no way to actually delete files. I tried to think of a way, but I can't think of any way to do it. NOTE: This is flat, no SQL. Here's the core code for the uploader: <? //print_r($_POST); if($_POST["action"] == "Upload Image") { unset($imagename); if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES; if(!isset($_FILES['image_file'])) $error["image_file"] = "An image was not found."; $imagename = basename($_FILES['image_file']['name']); //echo $imagename; if(empty($imagename)) $error["imagename"] = "The name of the image was not found."; if(empty($error)) { $newimage = $f_user . "/" . $imagename; //echo $newimage; $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; } } ?> <center><form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>"> <input type="file" name="image_file" size="20"> <br><br><input type="submit" value="Upload Image" name="action"> </form></center> <div align="center"><br> <? if(is_array($error)) { while(list($key, $val) = each($error)) { echo $val; echo "<br>\n"; } } ?> <? $handle = @opendir($f_user); if(!empty($handle)) { while(false !== ($file = readdir($handle))) { if(is_file($f_user . "/" . $file)) echo '<a href=http://www.reflexprojects.net/rs/upload/'. $f_user .'/'. $file .'>'. $file .'</a><br><br>'; } } closedir($handle); ?> The best solution would be for the files to list in a 2-column table, with the name/link on the left (<a href=http://www.reflexprojects.net/rs/upload/'. $f_user .'/'. $file .'>'. $file .'</a>) and the 'delete' option on the right. CODEKEY: $f_user = username (stores files in a folder named with their username) Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/ Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 bump. It doesn't have to be in a table, it's just that would be best. Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338513 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 although...There's probably no such thing, but is there a way to 'explode' different files? Stupid question, but if you could, I could work this out. Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338516 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338525 Share on other sites More sharing options...
madspof Posted August 31, 2007 Share Posted August 31, 2007 So do you want to list your images in a directroy and then to the right of them place a link where users can delete their pics? And it probaly not a gd idea to keeping posting to your own topic as you will get banned. Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338528 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 that's what I want to do, yes. And I believe in the rules it said to bump your topic every once in a while. This was opened about 3 hours ago, and I am bumping it every half hour to every hour Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338529 Share on other sites More sharing options...
madspof Posted August 31, 2007 Share Posted August 31, 2007 I just saw two posts straight after each other anyway To list your code you will need some thing like this <?php $files = array(); $dir=opendir("./PLACEDIRHERE"); 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"; ?> I have made the list for you now you need to make the delete.php script just a hint you will need to use a combination of the get command and the unlink command Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338532 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 It didn't work.. Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338536 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 Can I bump it now? Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338626 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 (1 and a half hours later) bump Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338697 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 <?php $file = $f_user"/"$_GET['del']; if(unlink($file)) { echo "The file was deleted successfully."; } else { echo "There was an error trying to delete the file."; } ?> The code I'm using with yours. I typed the directory ID wrong. So what's wrong with this? $f_user is there because the folder is the user's username. EG. Testuser uploading test.gif would end up with the file in /testuser/test.gif. Anyways, problems? Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338742 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 last bump, if no answer, I'm giving up. Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338794 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Author Share Posted August 31, 2007 EDIT: Oh, sorry, bumped it. Quote Link to comment https://forums.phpfreaks.com/topic/67436-delete-function-on-uploader/#findComment-338819 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.