Jump to content


opendir() issue

  • Please log in to reply
2 replies to this topic

#1 joshstimpy

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 April 2006 - 11:41 PM

i want to load my files from a directory into an array. my code thus far is
#set up the array

$dir = "/images/hand/";

$files = array();
$directory = opendir($dir);
while($filename = readdir($directory)){
if(strlen($filename) > 2){
array_push($files, $filename);

foreach($files as $name)
echo "<img src='$name.jpg'> <br>";

i get the error:
Warning: opendir(www.sbwelding.com//images/hand/) [function.opendir]: failed to open dir: Invalid argument in C:\serve\www\hand.php on line 12

Warning: readdir(): supplied argument is not a valid Directory resource in C:\serve\www\hand.php on line 13
i have php 5 and have tried using the whole url and it doesnt work. if u have heard of this problem before i would appreciate the help. i am trying to make the script automatically load every pic in my folder.

#2 ypirc

  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 22 April 2006 - 11:45 PM

You probably need to remove the first slash and make it "images/hand" instead. Also, you may look into using the full path, NOT the "url". Also, I suggest this function [a href=\"http://www.php.net/glob\" target=\"_blank\"]http://www.php.net/glob[/a]

#3 joshstimpy

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 April 2006 - 03:44 PM

thanks the glob() worked great!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users