nblackwood Posted August 21, 2010 Share Posted August 21, 2010 I have a file system browser i'm writing for a client. I would like to know if there's a way to determine if an object is a directory or file, so I can display a proper icon next to it depending on what it is. Any help is appreciated. Quote Link to comment Share on other sites More sharing options...
trq Posted August 21, 2010 Share Posted August 21, 2010 is_dir. Quote Link to comment Share on other sites More sharing options...
nblackwood Posted August 21, 2010 Author Share Posted August 21, 2010 Tried that, and i've also tried is_file and file_exists. No matter what I do, it either displays the folder icon or file icon but doesn't properly check which one it is. Quote Link to comment Share on other sites More sharing options...
trq Posted August 21, 2010 Share Posted August 21, 2010 Care to post the relevant code? Quote Link to comment Share on other sites More sharing options...
nblackwood Posted August 21, 2010 Author Share Posted August 21, 2010 There's more to the code, but here is the part that is relevant to this issue. <?php foreach ($d as $key => $val) { if(is_dir($val)) { $icon = 'images/Folder.png'; } else { $icon = 'images/File.png'; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted August 21, 2010 Share Posted August 21, 2010 Are you passing the complete path to is_dir()? Quote Link to comment Share on other sites More sharing options...
nblackwood Posted August 21, 2010 Author Share Posted August 21, 2010 Also tried that, but am getting same results. Quote Link to comment Share on other sites More sharing options...
trq Posted August 21, 2010 Share Posted August 21, 2010 We need to see your actual code in order to be of any help. ps: We have tags. Quote Link to comment Share on other sites More sharing options...
nblackwood Posted August 21, 2010 Author Share Posted August 21, 2010 Excuse the sloppyness... <?php $DefaultDir = "c:\\"; if(!isset($_POST['NewDir'])) { $d = @scandir($DefaultDir); } else { $d = @scandir($_POST['NewDir']); } function ChangeDirectory() { @chdir($_POST['NewDir']); } if(is_dir($val)) { $icon = 'images/Folder.png'; } else { $icon = 'images/File.png'; } if(isset($_POST['Go'])) { ChangeDirectory(); @getcwd(); } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <p> <input name="NewDir" type="text" /><input name="Go" type="submit" value="Go"/> <?php foreach ($d as $key => $val) { ?> <table width=auto height=auto border=0> <tr> <td><img src="<?php echo $icon;?>" width=16 height=16></td> <td><?php echo $val;?></td> <td><input name="cmd[]" type="checkbox" value="<?php echo $val;?>"/></td> </tr> </table> <?php } "<br><br>" ?> <?php $Command = $_POST['cmd']; if(isset($_POST['submit'])) { ?> <table width="auto" height="auto" border="0"> <tr> <td><?php for ($i=0; $i < count($_POST['cmd']);$i++) { echo "<br>".$_POST['cmd'][$i]; } ?></td> </tr> </table> <?php } ?> <p> <input name="submit" type="submit" value="Submit"> </p> </form> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2010 Share Posted August 21, 2010 You are kind of asking someone who is not standing right beside you to magically know what your code is (and the few lines you did post is not all the relevant code because that does not show how you are getting the data and what processing you are doing to it), what the actual data values are, what data value is failing (and what are some of the ones that work), and what results you ARE getting for those data values vs the expected results. Had you simply included in your first post in this thread - 1) All the code (someone could duplicate the problem in a few minutes and tell you what to do to fix it), 2) Some actual data values you are using that work and does not work, 3) What result you are getting for each piece of that data. I'm going to guess this has something to do with slashes /, but since you haven't shown anything you have seen in front of you when you do this. it's kind of hard to guess what sort of problem you are having. Quote Link to comment Share on other sites More sharing options...
trq Posted August 21, 2010 Share Posted August 21, 2010 Um, the check needs to go within your foreach loop. Quote Link to comment Share on other sites More sharing options...
nblackwood Posted August 21, 2010 Author Share Posted August 21, 2010 ok, thanks for your help. I'll try that. 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.