Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

Problem with while ($ourItem = readdir($ourDirList))

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

Problem with while ($ourItem = readdir($ourDirList))

Postby Americanhorizon » Sun Dec 18, 2011 1:23 pm

Hi, i'm new in forum e in PHP coding. I've a problem with this simple operation that i've created to found any folder and file into a specific directory
Code: Select all
?php



// declare the folder

$ourDir = "/miaCartella";



// prepare to read directory contents

$ourDirList = @opendir($ourDir);



// loop through the items

while ($ourItem = readdir($ourDirList))

{

   // check if it is a directory

   if (is_dir($ourItem))

   {

      echo "directory: $ourItem <br />";

   }

   // check to see if it is a file

   if (is_file($ourItem))

   {

      echo "file: $ourItem <br />";

   }

}



closedir($ourDirList);



?>


I'm trying this code with easyPHP, but when i launch it, it give me this two errors
Warning: readdir() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP\www\recuperarelistafolderefile.php on line 19

Warning: closedir() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP\www\recuperarelistafolderefile.php on line 47
Americanhorizon
New php-forum User
New php-forum User
 
Posts: 16
Joined: Sun Dec 18, 2011 1:20 pm

Re: Problem with while ($ourItem = readdir($ourDirList))

Postby egami » Mon Dec 19, 2011 6:46 am

I believe your path is wrong. You're using an absolute path, and I believe you're looking for a relative path.

If this directory resides in the current directory of your script, add a period before the forward slash.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Problem with while ($ourItem = readdir($ourDirList))

Postby Americanhorizon » Mon Dec 19, 2011 10:01 am

egami wrote:I believe your path is wrong. You're using an absolute path, and I believe you're looking for a relative path.

If this directory resides in the current directory of your script, add a period before the forward slash.

works, but with some problem. into miaCartella i've placed some jpg. With this code i would want to retrieve the name of those files, instead when i execute it, this is the result:
directory: .
directory: ..

why?
Americanhorizon
New php-forum User
New php-forum User
 
Posts: 16
Joined: Sun Dec 18, 2011 1:20 pm

Re: Problem with while ($ourItem = readdir($ourDirList))

Postby egami » Mon Dec 19, 2011 10:19 am

/miaCartella

This means its at the root of the operating system.
Is this what you want? is this where your files are?

Or are they embedded elsewhere?
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Problem with while ($ourItem = readdir($ourDirList))

Postby Americanhorizon » Mon Dec 19, 2011 10:45 am

egami wrote:/miaCartella

This means its at the root of the operating system.
Is this what you want? is this where your files are?

Or are they embedded elsewhere?

no
miaCartella is a folder contained into
C:\Program Files (x86)\EasyPHP\www
Americanhorizon
New php-forum User
New php-forum User
 
Posts: 16
Joined: Sun Dec 18, 2011 1:20 pm

Re: Problem with while ($ourItem = readdir($ourDirList))

Postby egami » Mon Dec 19, 2011 1:47 pm

Then remove the forward-slash at the beginning of the thing, so it looks like..


$ourDir = 'miaCartella/';
Or..

$ourDir = 'C:\Program Files (x86)\EasyPHP\www\miaCartella';
// or however you would write that for Windows....
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to Your Scripts

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.