Jump to content

opendir() issue


joshstimpy

Recommended Posts

i want to load my files from a directory into an array. my code thus far is
<?php
#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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.