amat78 Posted May 9, 2011 Share Posted May 9, 2011 I am attempting to us glob to display contents of a users folder using a session variable. Example: I have a session variable called department $row_fullname['department']; In department I have the name of the department the user belongs to such as: office, plant, maintenance, and groundskeeping I created a folder called docs inside of docs there are 4 subfolders called office, plant, maintenance, and groundskeeping I found this code which will display the contents of the folder: <?php $files = glob( './docs/office/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/office/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?> The above code works fine, but I would like it to only display the contents of a departments folder only if the user is part on that department. Here is an example that I know is completely wrong but it may help explain what I am trying to do. <?php ]<?php $files = glob( './docs/echo $row_fullname['department'];/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/echo $row_fullname['department'];/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?> Thanks for your time Quote Link to comment https://forums.phpfreaks.com/topic/235951-use-glob-to-display-contents-of-a-folder-based-on-a-session-variable/ Share on other sites More sharing options...
wildteen88 Posted May 9, 2011 Share Posted May 9, 2011 You're sort of one the right track. The issue you have is variables are not parsed within single quotes. You should instead concatenate your variable into the string <?php $files = glob( './docs/' . $row_fullname['department'] . '/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/' . $row_fullname['department'] . '/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235951-use-glob-to-display-contents-of-a-folder-based-on-a-session-variable/#findComment-1212947 Share on other sites More sharing options...
amat78 Posted May 9, 2011 Author Share Posted May 9, 2011 Worked perfectly. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/235951-use-glob-to-display-contents-of-a-folder-based-on-a-session-variable/#findComment-1212969 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.