Jump to content

Oikofugic

New Members
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Oikofugic

  • Rank
    Newbie
  1. Oikofugic

    Read folder

    Thanks for clearing it up for me. I understand now <?php $dir = "pics/"; // Open a directory, and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ if (is_file($dir.$file)) { echo '<img src=" '.$dir.$file.' " width="120px" height="120px"/>'; } } closedir($dh); } } ?>
  2. Oikofugic

    Read folder

    Hi ginerjim, as I previously posted I have it working, with help from the link provided by requinix, then Berand popped back with his RTFM which I initially thought was an abbreviation for something useful that I would find on that page. I copied his code and tried to implement it into what I had, assuming it would negate the need to strip out the dots, but ended up with Undefined variable warning. It might have ultimately been for a more elegant solution Barand suggested, but as I had working anyway, I figured a partial solution with no explanation was not at this time necessary. This is what I was trying, but as you can no doubt tell I'm getting muddled <?php $dir = "pics/"; $file =""; // Open a directory, and read its contents if (is_file($dir.$file)) { if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ echo "<img src=\"$dir$file\" width=\"120px\" height=\"120px\"/>"; } closedir($dh); } } ?> I have tried various combinations etc So attempting to defile $file, but not quite sure as to why
  3. Oikofugic

    Read folder

    Hi Barand, Have tried with your suggestion, no joy unfortunately, undoubtedly my lack of understanding, but thanks anyway..
  4. Oikofugic

    Read folder

    Thanks requinix, It's still foo bar tbh, but got it working. Ta <?php $dir = "pics/"; $dh = opendir($dir); while (false !== ($file = readdir($dh))) { $pos = strrpos($file, '.'); if (false !== $pos && strlen($file) > $pos + 1) { $ext = substr($file, $pos + 1); echo '<img src="pics/'.$file.'" width="120px" height="120px"/>'; } } ?>
  5. Oikofugic

    Read folder

    Thanks for your reply, but there is only one image in the folder and nothing else.
  6. Oikofugic

    Read folder

    Hi all, I'm trying to echo all the files in the folder 'pics' <?php $dir = "pics/"; // Open a directory, and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ echo '<img src="pics/' .$file . '" width="120px" height="120px" />'; } closedir($dh); } } ?> The above code outputs the following. (there is only one image in the folder) So the code gets the image correctly and works with multiple images in the folder, but also produces two broken pathways at the beginning. <img src="pics/." width="120px" height="120px" /><img src="pics/.." width="120px" height="120px" /><img src="pics/j1.jpg" width="120px" height="120px" /> My question is why, I can't figure out what is happening. Any pointers or explanations would be appreciated. Cheers for your time. Paul
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.