jakebur01 Posted February 20, 2009 Share Posted February 20, 2009 I have this script that pulls directories via ftp and displays them. I am trying to implement to where if $standard=2 then it will display the directory "secure". if $standard=1 then it will exclude the directory "secure." function ShowFiles() { $conn = DoConn(); $currDir = ""; // Get the name of the current directory if(isset($_GET["currDir"])) $currDir = $_GET["currDir"]; else $currDir = ftp_pwd($conn); // Retrieve a list of files and directories // and display the appropriate icon for each $fList = @ftp_nlist($conn, $currDir); // We will work out the parent directory $parentDir = strrev($currDir); $parentDir = ereg_replace("^[a-zA-Z0-9\-]*/", "", $parentDir); $parentDir = strrev($parentDir); ?> <a href="javascript:history.go(-1)"> <img src='images/back.gif'> </a> <a href="dealer_downloads.php"><img src="images/home.gif"></a> <br> <?php for($i = 0; $i < sizeof($fList); $i++) { // We will remove the parent directory (if any) // from the name of the file that gets displayed $trimFile = ereg_replace("^$currDir", "", $fList[$i]); // Remove any forward slash at front of name $trimFile = ereg_replace("^/", "", $trimFile); if(@ftp_chdir($conn, $fList[$i])) { @ftp_cdup($conn); ?> <img src='images/folder.gif'> <a href='dealer_downloads.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } else { ?> <img src='images/file.gif'> <a href='dealer_downloads.php?command=getFile&currFile=<?php echo $fList[$i]; ?>&currDir=<?php echo $currDir; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } } } Link to comment https://forums.phpfreaks.com/topic/146133-solved-excluding-directory/ Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 Your code is messy so instead of doing it for you, I will explain the logic. if ($currDir == "secure" && $secure == 1) { // skip/continue the script. continue; // not sure this will work, cause I cannot tell if you are looping through each directory/where it starts. } I would practice indenting your code properly as it is just a mess if you do not. It really turns people off from helping you, honestly. Link to comment https://forums.phpfreaks.com/topic/146133-solved-excluding-directory/#findComment-767181 Share on other sites More sharing options...
jakebur01 Posted February 20, 2009 Author Share Posted February 20, 2009 Thanks for the tip on indenting. I will work on that. I tried this, but it isn't working. I also used ereg_replace on the "secure" directory which did work, but it left the image. if(@ftp_chdir($conn, $fList[$i])) { @ftp_cdup($conn); if ($fList[$i]==secure) { } else {?> <img src='images/folder.gif'> <a href='dealer_downloads.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } } Link to comment https://forums.phpfreaks.com/topic/146133-solved-excluding-directory/#findComment-767187 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 if (strtolower($fList[$i]) == "secure" && $standard == 1) { } I do not know if secure is all lowercase, just incase it is not, invoked the strtolower function for checking, and added the "&&" so it checks if standard is 1, if it is and the folder is secure then it should enter that if. Link to comment https://forums.phpfreaks.com/topic/146133-solved-excluding-directory/#findComment-767193 Share on other sites More sharing options...
jakebur01 Posted February 20, 2009 Author Share Posted February 20, 2009 hmm.. It is still not catching it. I even tried if (strtolower($fList[$i]) == "secure") and it still did not work. Link to comment https://forums.phpfreaks.com/topic/146133-solved-excluding-directory/#findComment-767200 Share on other sites More sharing options...
jakebur01 Posted February 20, 2009 Author Share Posted February 20, 2009 ohh.. it may have a forward slash in front of it??... $fList[$i] outputs "dealer_downloads.php?command=listFiles&currDir=/secure" in the browser I tried this. It doesn't do anything yet. if ($fList[$i] == "/secure" && $standard == 1) { echo"no secure"; } else {?> <img src='/images/folder.gif'> <a href='dealer_downloads.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } $fList[$i] does output /secure though when I echoed it out on the page Link to comment https://forums.phpfreaks.com/topic/146133-solved-excluding-directory/#findComment-767204 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 ohh.. it may have a forward slash in front of it??... $fList[$i] outputs "dealer_downloads.php?command=listFiles&currDir=/secure" in the browser That would do it, add it in or remove it before the if then see what happens. Link to comment https://forums.phpfreaks.com/topic/146133-solved-excluding-directory/#findComment-767210 Share on other sites More sharing options...
jakebur01 Posted February 20, 2009 Author Share Posted February 20, 2009 It worked when I changed my double quotes to single quotes. Thank you premiso and thanks again for the tip. Link to comment https://forums.phpfreaks.com/topic/146133-solved-excluding-directory/#findComment-767231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.