enjoirock Posted November 7, 2010 Share Posted November 7, 2010 Hi all - I have a form that let's a user upload an image to their specified folder. The folder is determined by the "password" the user inputs. The "password" is really just the folder name on my server, so if "michael83" was entered as a password, the directory would be "images/uploaded/michael83". That works great now, thanks to a forum user, litebearer. Thanks again. Here's my second question: I'm working on a "history" page so that a user can input their "password" and view their upload history. The form works right now. If you enter a "password" (folder name) that exists, the code will spit out the contents / files. So, now I'm looking for two things: (1) if a user enters a "password" (folder name) that exists, but there are no files in the folder, "There are no files in the $dir directory." will be echoed; and (2) if a "password" (folder name) is entered that does NOT exist, "The directory $dir does not exist." will be echoed. Here's my code so far (minus the if statements I'm looking for): $dir = $_POST['password']; $path = "images/uploaded/". $dir; $dir_handle = @opendir($path); while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." ) continue; if(isset($_POST['Submit'])) $url = "http://www.mysite.com/". $path . "/" . $file; { echo "<a href=\"$url\">$url</a><br />"; }} closedir($dir_handle); As always, many thanks in advance for any help on this. Quote Link to comment Share on other sites More sharing options...
enjoirock Posted November 7, 2010 Author Share Posted November 7, 2010 I'm a little bit closer: $dir = $_POST['password']; $path = "images/uploaded/". $dir; $dir_handle = @opendir($path); if(is_dir($path)){ echo ("Listing for directory <strong>$dir</strong>:<br><br>"); } else{ echo ("Sorry, the directory <strong>$dir</strong> does not exist."); echo '<p>If you continue to have problems, please <a href="#">contact us</a>.</p>'; } while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." ) continue; $url = "http://www.mysite.com/". $path . "/" . $file; { echo "<a href=\"$url\">$url</a><br />"; } } if(isset($_POST['Submit'])) closedir($dir_handle); The problem I'm seeing now is right off the bat (before a password is even entered / submitted), the code spits out (showing on the page) the folders/directories within the "uploaded" folder as follows: ----- Listing for directory : http://www.mysite.com/images/uploaded//michael83 ----- Probably should have mentioned once again that I'm new to PHP. Anyway, thanks again to anyone that can help out. 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.