Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing opendir with PHP Pages Component for Joomla 1.5
    primarykey
    data
    text
    <p>I have a website running on Joomla! 1.5 (can't upgrade because of template issue).<br> On this site, I have a page where members can find some important files, needed for the membership in our club.</p> <p>I arranged these files in some folders, all using the same naming convention ( *yyyy-mm-dd_documentName* ).</p> <p>To make things easier, I want to automaticly list the files, using some formatting.</p> <p>As Joomla doesn't allow PHP to be entered in articles, I installed the <a href="https://code.google.com/p/joomla-php/downloads/detail?name=com_php-0.2-alpha1-J1.5.zip" rel="nofollow">PHP Pages Component</a>.<br> This component allows you to create pages and link to them via e.g. the menu bar.</p> <p>Too list those files, I want to use the PHP's opendir function, opening the folder and run over the folder to read the file names and format them.<br> This is the code I was using for that:</p> <pre><code>if($handle = opendir('/media/files/')) { while(false !== ($entry = readdir($handle))) { echo $entry; } closedir($handle); } </code></pre> <p>This gave an error as the component starts every relative path from it's own dir, ignoring the first / for some reason.<br> So I tried to fix that by entering the full URL (starting from http://). </p> <p>Still not fixed, the new error now is (bestanden.php is the PHP page)</p> <blockquote> <p><strong>Warning:</strong> opendir(<a href="http://www.example.com/media/files" rel="nofollow">http://www.example.com/media/files</a>) [function.opendir]: failed to open dir: not implemented in <strong>/home/user/public_html/components/com_php/files/bestanden.php</strong> on line <strong>38</strong></p> </blockquote> <p>Someone advised me to use the ftp-handlet (which is also supported).<br> The syntax for this apperantly is <em><a href="ftp://user:password@ftp.example.com" rel="nofollow">ftp://user:password@ftp.example.com</a></em><br> I made a seperate account for this, ending up immediately at the right dir, preventing cross-dir attacks. This does work if I manually try this in my browser (except that it still asks for credentials).<br> But this didn't work either.</p> <p>I'm running out of ideas.<br> Can anyone help me?</p> <p><strong>SOLUTION</strong></p> <p>Thanks to @Lodder</p> <pre><code>&lt;ul&gt; &lt;?php $path = JPATH_SITE . '/media/files/nieuwsbrieven/'; $files = JFolder::files($path); foreach ($files as $file) { // Strip extension and save name to display it $name = substr($file, 0, strrpos($file, '.')); // Exclude the index I placed inside the dir to prevent direct surfing to the folder if($name != "index") { echo "&lt;li&gt;&lt;a href='/media/files/nieuwsbrieven/" . $file . "' title='Nieuwsbrief " . $name . "' target='_blank'&gt;Nieuwsbrief " . $name . "&lt;/a&gt;&lt;/li&gt;"; } } ?&gt; &lt;/ul&gt; </code></pre> <p><em>Result</em></p> <ul> <li>Nieuwsbrief 2013-04-03</li> <li>Nieuwsbrief 2013-04-19</li> <li>Nieuwsbrief 2013-05-16</li> <li>Nieuwsbrief 2013-06-19</li> <li>Nieuwsbrief 2013-07-17</li> <li>Nieuwsbrief 2013-08-28</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload