<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1043197" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1043197</link>
    <description></description>
    <language>en</language>
          <item>
    <title>The file system is going to</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238935</link>
    <description> &lt;p&gt;The file system is going to be at _least_ as fast as any database for simple reads like this.  &lt;/p&gt;
&lt;p&gt;If the contents of the folders are going to be changing a lot, especially mid-user-session, you may want to consider a &#039;read once and cache for the user session approach&#039; suggested. Changing (or maybe even touching?)the directory&#039;s contents will likely change the order of scandir&#039;s results, which may throw someone somewhere down the line...&lt;/p&gt;
&lt;p&gt;Numerical folders for each &#039;page&#039; as you suggest isn&#039;t a bad idea either!&lt;/p&gt;
&lt;p&gt;My guess would be the numerical folders for each page would be the &#039;most efficient&#039; (fastest) if that is what you are after, though would take a bit more care to maintain.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;br /&gt;
Shaggy&lt;/p&gt;
 </description>
     <pubDate>Wed, 04 Mar 2009 03:14:23 +0000</pubDate>
 <dc:creator>Shaggy</dc:creator>
 <guid isPermaLink="false">comment 1238935 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>yeah, I did try that,</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238930</link>
    <description> &lt;p&gt;yeah, I did try that, printed the array, and with my clause of &lt;code&gt;$loop_count &amp;lt; 5&lt;/code&gt; in the while, it did stop at the number I changed the &lt;code&gt;&amp;lt; 5&lt;/code&gt; to.&lt;br /&gt;
The array only held 2 folder names, or 5 (etc)&lt;/p&gt;
&lt;p&gt;I just like throwing things out there for discussion. I enjoy writing code to a good standard, and there&#039;s often something someone else knew I didn&#039;t - a more efficient method or even just a slight tweak.&lt;/p&gt;
&lt;p&gt;Although I still don&#039;t know if adding all subfolder names to a session array for when the user goes to other pages is best, or if another way would be better.&lt;br /&gt;
I don;t see another way (without DB) to determine which subolders would be on what page.&lt;br /&gt;
Perhaps I could name the folders numerical, 1, 2, 3, 4 etc, but that seems weird somehow..?&lt;/p&gt;
 </description>
     <pubDate>Wed, 04 Mar 2009 01:34:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1238930 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>I don&#039;t see anything wrong</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238928</link>
    <description> &lt;p&gt;I don&#039;t see anything wrong with your proposed solution...&lt;br /&gt;
The docs mention readdir($handle) returns boolean false when no results are available (You&#039;re done), which will cause your while clause to evaluate to false, and the loop to stop executing.&lt;/p&gt;
&lt;p&gt;If you&#039;re still not sure, give it a little test run... Create 4 elements, add a debug &#039;echo&#039; or two, and see how things shake out.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;br /&gt;
Shaggy.&lt;/p&gt;
 </description>
     <pubDate>Wed, 04 Mar 2009 00:54:28 +0000</pubDate>
 <dc:creator>Shaggy</dc:creator>
 <guid isPermaLink="false">comment 1238928 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>I misunderstood what the</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238923</link>
    <description> &lt;p&gt;I misunderstood what the file structure you were looking for. Will check it more when I get home.&lt;/p&gt;
 </description>
     <pubDate>Tue, 03 Mar 2009 22:04:34 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1238923 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>It&#039;s for images for a</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238922</link>
    <description> &lt;p&gt;It&#039;s for images for a portfolio.&lt;/p&gt;
&lt;p&gt;Main folder with xx sub folders in it, each sub folder has xx images in (one subfolder for each &#039;portfolio job&#039;). So my code in my first post does actually get folder names (not files).&lt;/p&gt;
&lt;p&gt;The sub folders will likely never be more than 10 images, and not more than 100 sub-folders ever.&lt;/p&gt;
&lt;p&gt;So dir is scanned and subfolder names are stored in an array. Then a foreach on the array displaying the first image in the sub-dir for that loop. Each image is a link to another page (php file) with GET info of the folder name, which then displays all the images from that sub-folder.&lt;/p&gt;
&lt;p&gt;The image titles and  other text is unfortunately stored in a file accessed when required. I know a database would have been really useful here, but it would have been the only use on the entire site for a DB, so I didn&#039;t bother with one.&lt;/p&gt;
&lt;p&gt;@ Greg (no, you, not me...)&lt;br /&gt;
Isn&#039;t your code the same mine as in my first post?&lt;br /&gt;
I know you have count() and I increment a var, but isn&#039;t it doing the same thing?&lt;br /&gt;
(albeit yours looks more efficient than mine) &lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;Greg K&lt;/em&gt; wrote:&lt;/div&gt;2. What if there is 1000 files, this would waste resources loading up a complete directory list&lt;/div&gt;Firstly there wont be (sites can have known future proof limitations)&lt;/p&gt;
&lt;p&gt;And without storing all subfolders in an array, how else will I know which are to be on page 1, page 2, page 3 etc?&lt;br /&gt;
Example: I display 10 images per page (one from each subfolder), and have 50 images total.&lt;br /&gt;
How would I determine, and get, only the LAST 10 images for page 5?&lt;/p&gt;
 </description>
     <pubDate>Tue, 03 Mar 2009 18:42:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1238922 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>This would be a recommended</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238920</link>
    <description> &lt;p&gt;This would be a recommended way to do it if you were needing some kind of sort of the files, however with the example given of just grabbing the first XX, there are two issues:&lt;/p&gt;
&lt;p&gt;1. scandir will return all files including current (.) and parent (..) so will still need to be looped through to eliminate those&lt;/p&gt;
&lt;p&gt;2. What if there is 1000 files, this would waste resources loading up a complete directory list&lt;/p&gt;
&lt;p&gt;The following is a simplified version, and also uses the assumption that not only would you want to hide .htaccess, but any file starting with .ht (as by default apache is set to not allow access to them anyhow)&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$dh &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;opendir&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;test&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$aryFiles &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= array();&lt;br /&gt;&lt;br /&gt;while (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$aryFiles&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;5 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;amp;&amp;amp; (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;readdir&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$dh&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;))!==&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) {&lt;br /&gt;&amp;nbsp;&amp;nbsp; if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;.&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;..&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;substr&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)!=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;.ht&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$aryFiles&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[] = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;closedir&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$dh&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;The reason I placed the count of the array first is because if there are already 5 items, no need to actually read the directory at all. (On an AND (&amp;amp;&amp;amp;), the first false value stops any other conditions from executing).&lt;/p&gt;
&lt;p&gt;-Greg&lt;/p&gt;
 </description>
     <pubDate>Tue, 03 Mar 2009 17:41:02 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1238920 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Are you using them for</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238919</link>
    <description> &lt;p&gt;Are you using them for displaying pages stored in a folder?&lt;/p&gt;
 </description>
     <pubDate>Tue, 03 Mar 2009 16:39:51 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1238919 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Hmm, so get all then split</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238918</link>
    <description> &lt;p&gt;Hmm, so get all then split into multi-dim-array for each page. &lt;/p&gt;
&lt;p&gt;Perhaps also storing the array in a session for each page too to avoid repeat dir scanning... interesting ideas..&lt;/p&gt;
 </description>
     <pubDate>Tue, 03 Mar 2009 15:55:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1238918 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>So you are wanting to get</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/readdir-pages#comment-1238915</link>
    <description> &lt;p&gt;So you are wanting to get the first &#039;n&#039; elements from a &lt;a href=&quot;http://us.php.net/manual/en/function.scandir.php&quot;&gt;scandir()&lt;/a&gt;?  I would use the &lt;a href=&quot;http://us.php.net/manual/en/function.array-chunk.php&quot;&gt;array_chunk()&lt;/a&gt; function to split it up in chunks, and then take the first one.&lt;/p&gt;
 </description>
     <pubDate>Tue, 03 Mar 2009 15:09:52 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1238915 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
