Re: [PHP] Readdir() question

2008-09-12 Thread Luke
When I need to do 'filesystem' type things I use MySQL to map all of the
files. This offers lot's of versatility in that you could just make a single
folder called filesystem and have all of your files in the root of that
folder - then use mysql to map virtual folders and structures and such.

2008/9/12 Jochem Maas [EMAIL PROTECTED]

 Nathan Rixham schreef:

 Jochem Maas wrote:

 Nathan Rixham schreef:

 Stut wrote:
 maybe this is into coding standards and ethics.. but this may be
 acceptable:
 if( !defined('__DIR__') ) {
  define('__DIR__' , dirname(__FILE__));
 }

 however realistically you'd have to do this in every file and nto just
 in one include


 which would give an error on second and subsequent define()s

 yet if(!defined... it's already defined so won't be defined subsequent
 times :)


 my bad


 still crap though


 yes :-P


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Luke Slater


Re: [PHP] Readdir() question

2008-09-12 Thread Jochem Maas

Luke schreef:

When I need to do 'filesystem' type things I use MySQL to map all of the
files. This offers lot's of versatility in that you could just make a single
folder called filesystem and have all of your files in the root of that
folder - then use mysql to map virtual folders and structures and such.


I don't understand what you mean, can you elaborate?


2008/9/12 Jochem Maas [EMAIL PROTECTED]


Nathan Rixham schreef:


Jochem Maas wrote:


Nathan Rixham schreef:


Stut wrote:
maybe this is into coding standards and ethics.. but this may be
acceptable:
if( !defined('__DIR__') ) {
 define('__DIR__' , dirname(__FILE__));
}

however realistically you'd have to do this in every file and nto just
in one include


which would give an error on second and subsequent define()s

yet if(!defined... it's already defined so won't be defined subsequent

times :)


my bad



still crap though



yes :-P


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php








--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Readdir() question

2008-09-12 Thread Luke
Ok,

one folder on your webserver, and put all of the files that you want to
include on your website/system in this folder (also uploading into this
folder); just in the root of that folder, so say you wouldn't have anymore
folders under it.

Make a table called 'Files,' containing:

ID
Name
Type
true_location
virtual_location

(or similar depending on your needs, you might also want a folders table,
perhaps this will increase speed if you are visually displaying the entire
display system.)

the Name, name of the file
Type, type of file, I have this in just so i can easily tell what file it is
and what to do without having to execute more scripts.
true_location, the real location and filename of the file that is placed in
your file
virtual_location, made up location that forms your filesystem

The advantages of mapping real files in a virtual location is that you and
the user can interact with the virtual location like it is really mapped and
keep the versatility of MySQL. Since reading several pieces of
information from MySQL is much faster than reading from files to get it.

For an upload system you would need to write a PHP script on the upload of
the file to add entries to the table. If you are initially placing many
files in there you may want to write a perl/shell/php script to enter all of
the initial file entries for the table for you.

2008/9/12 Jochem Maas [EMAIL PROTECTED]

 Luke schreef:

 When I need to do 'filesystem' type things I use MySQL to map all of the
 files. This offers lot's of versatility in that you could just make a
 single
 folder called filesystem and have all of your files in the root of that
 folder - then use mysql to map virtual folders and structures and such.


 I don't understand what you mean, can you elaborate?


 2008/9/12 Jochem Maas [EMAIL PROTECTED]

 Nathan Rixham schreef:

 Jochem Maas wrote:

 Nathan Rixham schreef:

 Stut wrote:
 maybe this is into coding standards and ethics.. but this may be
 acceptable:
 if( !defined('__DIR__') ) {
  define('__DIR__' , dirname(__FILE__));
 }

 however realistically you'd have to do this in every file and nto just
 in one include

 which would give an error on second and subsequent define()s

 yet if(!defined... it's already defined so won't be defined subsequent

 times :)

 my bad


 still crap though


 yes :-P


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php








-- 
Luke Slater
defiance.bounceme.net/dinosaur/


Re: [PHP] Readdir() question

2008-09-12 Thread Nathan Rixham

Luke wrote:

Ok,

one folder on your webserver, and put all of the files that you want to
include on your website/system in this folder (also uploading into this
folder); just in the root of that folder, so say you wouldn't have anymore
folders under it.

Make a table called 'Files,' containing:

ID
Name
Type
true_location
virtual_location

(or similar depending on your needs, you might also want a folders table,
perhaps this will increase speed if you are visually displaying the entire
display system.)

the Name, name of the file
Type, type of file, I have this in just so i can easily tell what file it is
and what to do without having to execute more scripts.
true_location, the real location and filename of the file that is placed in
your file
virtual_location, made up location that forms your filesystem

The advantages of mapping real files in a virtual location is that you and
the user can interact with the virtual location like it is really mapped and
keep the versatility of MySQL. Since reading several pieces of
information from MySQL is much faster than reading from files to get it.

For an upload system you would need to write a PHP script on the upload of
the file to add entries to the table. If you are initially placing many
files in there you may want to write a perl/shell/php script to enter all of
the initial file entries for the table for you.

2008/9/12 Jochem Maas [EMAIL PROTECTED]


Luke schreef:


When I need to do 'filesystem' type things I use MySQL to map all of the
files. This offers lot's of versatility in that you could just make a
single
folder called filesystem and have all of your files in the root of that
folder - then use mysql to map virtual folders and structures and such.


I don't understand what you mean, can you elaborate?


2008/9/12 Jochem Maas [EMAIL PROTECTED]

Nathan Rixham schreef:

Jochem Maas wrote:

Nathan Rixham schreef:

Stut wrote:

maybe this is into coding standards and ethics.. but this may be
acceptable:
if( !defined('__DIR__') ) {
 define('__DIR__' , dirname(__FILE__));
}

however realistically you'd have to do this in every file and nto just
in one include

which would give an error on second and subsequent define()s

yet if(!defined... it's already defined so won't be defined subsequent


times :)

my bad


still crap though


yes :-P


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php










i just use DirectoryIterator combined with DOMDocument to create nested
deep directory listing xml files that I can use in any application; i
find the over head v low; and if it was to go high; I'd just cache the
results :p



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Readdir() question

2008-09-12 Thread Boyd, Todd M.
 -Original Message-
 From: Luke [mailto:[EMAIL PROTECTED]
 Sent: Friday, September 12, 2008 7:13 AM
 To: Jochem Maas
 Cc: [EMAIL PROTECTED]; php-general@lists.php.net
 Subject: Re: [PHP] Readdir() question
 
 Ok,
 
 one folder on your webserver, and put all of the files that you want
to
 include on your website/system in this folder (also uploading into
this
 folder); just in the root of that folder, so say you wouldn't have
 anymore
 folders under it.
 
 Make a table called 'Files,' containing:
 
 ID
 Name
 Type
 true_location
 virtual_location
 
 (or similar depending on your needs, you might also want a folders
 table,
 perhaps this will increase speed if you are visually displaying the
 entire
 display system.)
 
 the Name, name of the file
 Type, type of file, I have this in just so i can easily tell what file
 it is
 and what to do without having to execute more scripts.
 true_location, the real location and filename of the file that is
 placed in
 your file
 virtual_location, made up location that forms your filesystem
 
 The advantages of mapping real files in a virtual location is that you
 and
 the user can interact with the virtual location like it is really
 mapped and
 keep the versatility of MySQL. Since reading several pieces of
 information from MySQL is much faster than reading from files to get
 it.
 
 For an upload system you would need to write a PHP script on the
upload
 of
 the file to add entries to the table. If you are initially placing
many
 files in there you may want to write a perl/shell/php script to enter
 all of
 the initial file entries for the table for you.

---8--- snip

It would get a bit ugly when you started having files with the same name
being stored in that physical directory. Obviously, there are ways to
combat this (tack an identifier onto the file name, etc.) but it seems
like it's too much work when there is already a methodology in place
that works--the underlying filesystem.

I guess it would be faster if you cached file attributes (last mod time,
owner, etc.) every now and again on some sort of schedule, and read the
attributes from the table instead of the file itself... but you've still
got to do it in the scheduled job, and your data is stale. Maybe that's
okay, maybe that's not.


Todd Boyd
Web Programmer




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Readdir() question

2008-09-11 Thread Ben Stones
Hi,

I'm going to make a small browser based file system for ease of small
updates that I make frequently on my Website. First of all I want to loop
all the files on the same directory and to tell PHP read the same directory,
I think I'd need to use the magic constant I think its called, __DIR__ such
as:

?php
$dir=opendir(__DIR__);
while($files=readdir($dir)) {
echo $files;
}
?

But I get a few errors:

*Warning*: opendir(__DIR__) [function.opendir]: failed to open dir: No error
in *C:\wamp\www\Project1\index.php* on line *2*

*Warning*: readdir(): supplied argument is not a valid Directory resource in
*C:\wamp\www\Project1\index.php* on line *3

*Any help in the right direction will be appreciated!

Cheers.


Re: [PHP] Readdir() question

2008-09-11 Thread Stut

On 11 Sep 2008, at 13:12, Ben Stones wrote:

I'm going to make a small browser based file system for ease of small
updates that I make frequently on my Website. First of all I want  
to loop
all the files on the same directory and to tell PHP read the same  
directory,
I think I'd need to use the magic constant I think its called,  
__DIR__ such

as:

?php
$dir=opendir(__DIR__);
while($files=readdir($dir)) {
echo $files;
}
?

But I get a few errors:

*Warning*: opendir(__DIR__) [function.opendir]: failed to open dir:  
No error

in *C:\wamp\www\Project1\index.php* on line *2*

*Warning*: readdir(): supplied argument is not a valid Directory  
resource in

*C:\wamp\www\Project1\index.php* on line *3

*Any help in the right direction will be appreciated!


__DIR__ is not a valid constant (yet, I think it may be planned for  
5.3/6). You should be developing with notices on - this would have  
told you __DIR__ is wrong.


Use dirname(__FILE__) to get what you're after.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Readdir() question

2008-09-11 Thread Jay Blanchard
[snip]
I'm going to make a small browser based file system for ease of small
updates that I make frequently on my Website. First of all I want to
loop
all the files on the same directory and to tell PHP read the same
directory,
I think I'd need to use the magic constant I think its called, __DIR__
such
as:

?php
$dir=opendir(__DIR__);
while($files=readdir($dir)) {
echo $files;
}
?

But I get a few errors:

*Warning*: opendir(__DIR__) [function.opendir]: failed to open dir: No
error
in *C:\wamp\www\Project1\index.php* on line *2*

*Warning*: readdir(): supplied argument is not a valid Directory
resource in
*C:\wamp\www\Project1\index.php* on line *3

*Any help in the right direction will be appreciated!
[/snip]

This really is not the proper use if __DIR__ as it is based on a file
that you are trying to open. This is equivalent to dirname(__FILE__).
which will give you the path of the __FILE__ and hence the directory of
that file. In your case you should specify the file path in $dir

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Readdir() question

2008-09-11 Thread Jochem Maas

Ben Stones schreef:

Hi,

I'm going to make a small browser based file system for ease of small
updates that I make frequently on my Website. First of all I want to loop
all the files on the same directory and to tell PHP read the same directory,
I think I'd need to use the magic constant I think its called, __DIR__ such
as:


__DIR__ does not exist unless your using php5.3 ... and your not.

your still not bothering to develop with error_reporting set to 'full'
namely E_ALL | E_STRICT, probably it's set to E_ALL ^ E_NOTICE ... no idea what
I'm talking about?

read this: http://php.net/error_reporting



?php
$dir=opendir(__DIR__);
while($files=readdir($dir)) {
echo $files;
}
?

But I get a few errors:


code you write should check for errors, namely checking to see whether opendir()
failed or not, if it did fail output don't try to loop through the files using 
readdir(),
output an error message or something instead.



*Warning*: opendir(__DIR__) [function.opendir]: failed to open dir: No error
in *C:\wamp\www\Project1\index.php* on line *2*

*Warning*: readdir(): supplied argument is not a valid Directory resource in
*C:\wamp\www\Project1\index.php* on line *3

*Any help in the right direction will be appreciated!

Cheers.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Readdir() question

2008-09-11 Thread Nathan Rixham

Stut wrote:

On 11 Sep 2008, at 13:12, Ben Stones wrote:

I'm going to make a small browser based file system for ease of small
updates that I make frequently on my Website. First of all I want to loop
all the files on the same directory and to tell PHP read the same 
directory,
I think I'd need to use the magic constant I think its called, __DIR__ 
such

as:

?php
$dir=opendir(__DIR__);
while($files=readdir($dir)) {
echo $files;
}
?

But I get a few errors:

*Warning*: opendir(__DIR__) [function.opendir]: failed to open dir: No 
error

in *C:\wamp\www\Project1\index.php* on line *2*

*Warning*: readdir(): supplied argument is not a valid Directory 
resource in

*C:\wamp\www\Project1\index.php* on line *3

*Any help in the right direction will be appreciated!


__DIR__ is not a valid constant (yet, I think it may be planned for 
5.3/6). You should be developing with notices on - this would have told 
you __DIR__ is wrong.


Use dirname(__FILE__) to get what you're after.

-Stut


maybe this is into coding standards and ethics.. but this may be acceptable:
if( !defined('__DIR__') ) {
  define('__DIR__' , dirname(__FILE__));
}

however realistically you'd have to do this in every file and nto just 
in one include, as it changes on a per directory basis; hence why it'd 
/need/ to be a *magic* constant I guess :)


talked myself in and out of that one; but yet still worth a post i fear!

nath

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Readdir() question

2008-09-11 Thread Jochem Maas

Nathan Rixham schreef:

Stut wrote:

On 11 Sep 2008, at 13:12, Ben Stones wrote:

I'm going to make a small browser based file system for ease of small
updates that I make frequently on my Website. First of all I want to 
loop
all the files on the same directory and to tell PHP read the same 
directory,
I think I'd need to use the magic constant I think its called, 
__DIR__ such

as:

?php
$dir=opendir(__DIR__);
while($files=readdir($dir)) {
echo $files;
}
?

But I get a few errors:

*Warning*: opendir(__DIR__) [function.opendir]: failed to open dir: 
No error

in *C:\wamp\www\Project1\index.php* on line *2*

*Warning*: readdir(): supplied argument is not a valid Directory 
resource in

*C:\wamp\www\Project1\index.php* on line *3

*Any help in the right direction will be appreciated!


__DIR__ is not a valid constant (yet, I think it may be planned for 
5.3/6). You should be developing with notices on - this would have 
told you __DIR__ is wrong.


Use dirname(__FILE__) to get what you're after.

-Stut

maybe this is into coding standards and ethics.. but this may be 
acceptable:

if( !defined('__DIR__') ) {
  define('__DIR__' , dirname(__FILE__));
}

however realistically you'd have to do this in every file and nto just 
in one include


which would give an error on second and subsequent define()s

, as it changes on a per directory basis; hence why it'd 
/need/ to be a *magic* constant I guess :)


talked myself in and out of that one; but yet still worth a post i fear!


lol



nath




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Readdir() question

2008-09-11 Thread Nathan Rixham

Jochem Maas wrote:

Nathan Rixham schreef:

Stut wrote:
maybe this is into coding standards and ethics.. but this may be 
acceptable:

if( !defined('__DIR__') ) {
  define('__DIR__' , dirname(__FILE__));
}

however realistically you'd have to do this in every file and nto just 
in one include


which would give an error on second and subsequent define()s

yet if(!defined... it's already defined so won't be defined subsequent 
times :)


still crap though

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Readdir() question

2008-09-11 Thread Jochem Maas

Nathan Rixham schreef:

Jochem Maas wrote:

Nathan Rixham schreef:

Stut wrote:
maybe this is into coding standards and ethics.. but this may be 
acceptable:

if( !defined('__DIR__') ) {
  define('__DIR__' , dirname(__FILE__));
}

however realistically you'd have to do this in every file and nto 
just in one include


which would give an error on second and subsequent define()s

yet if(!defined... it's already defined so won't be defined subsequent 
times :)


my bad



still crap though



yes :-P

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] readdir() question

2006-08-16 Thread Richard Lynch
On Tue, August 15, 2006 11:00 pm, John Meyer wrote:
 Richard Lynch wrote:

 Do you really mean opendir() or do you mean readdir() ???


 readdir().

 The point is why do you need to put it as
 !==

 vs.
 !=

http://us3.php.net/manual/en/language.types.type-juggling.php

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] readdir() question

2006-08-15 Thread John Meyer
I have a script to list the files in a directory:

select name=letters
?php
$open = opendir(.);
while ($file = readdir($open) != false) {
?
option value=?=$file??=$file?/option
?php
}
?
/select
/form

And all I am getting are 1s.  I think I'm doing it right, what is the
disconnect?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] readdir() question

2006-08-15 Thread Tom Chubb

On 15/08/06, John Meyer [EMAIL PROTECTED] wrote:


I have a script to list the files in a directory:

select name=letters
?php
   $open = opendir(.);
   while ($file = readdir($open) != false) {
?
   option value=?=$file??=$file?/option
?php
   }
?
/select
/form

And all I am getting are 1s.  I think I'm doing it right, what is the
disconnect?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Straight from the PHP readdir help... http://uk2.php.net/readdir

?php
if ($handle = opendir('.')) {
  while (false !== ($file = readdir($handle))) {
  if ($file != .  $file != ..) {
  echo $file\n;
  }
  }
  closedir($handle);
}
?

It does however strip out '.' or '..' but I'm sure you'll get the hang of
it.
HTH


Re: [PHP] readdir() question

2006-08-15 Thread Richard Lynch
On Tue, August 15, 2006 12:04 pm, John Meyer wrote:
 I have a script to list the files in a directory:

 select name=letters
 ?php
   $open = opendir(.);
   while ($file = readdir($open) != false) {
 ?
   option value=?=$file??=$file?/option
 ?php
   }
 ?
 /select
 /form

 And all I am getting are 1s.  I think I'm doing it right, what is
 the
 disconnect?

It's not a readdir question.  It's an Order of Operations question.
:-)

$file = readdir($open) != false

You probably believe that PHP is going to magically know that you
want this bit:
readdir($open) != false
to be done first

But PHP can't read your mind.

It's going to look at the facts of the case.

= and != have equal priority in PHP,
and in case of a tie it will evaluate them left-to-right:

$file = readdir($open)

This gives you the name of the file.

PHP then does the != false bit, comparing the name of a file with false.

Unless your filename starts with one or more '0' characters, and then
has alpha characters for the first non-numeric characters after the
'0's, then it ain't gonna be equal to false, and it will always return
1.

'afile' != false  1
'filename' != false - 1
'000name' != false -- 0
'012name' != false -- 1

You really do need to put the parentheses in there, so PHP does things
in the rigth order, just like the manual says to:
http://php.net/readdir

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] readdir() question

2006-08-15 Thread John Meyer
Richard Lynch wrote:
 On Tue, August 15, 2006 12:04 pm, John Meyer wrote:
 I have a script to list the files in a directory:

 select name=letters
 ?php
  $open = opendir(.);
  while ($file = readdir($open) != false) {
 ?
  option value=?=$file??=$file?/option
 ?php
  }
 ?
 /select
 /form

 And all I am getting are 1s.  I think I'm doing it right, what is
 the
 disconnect?
 
 It's not a readdir question.  It's an Order of Operations question.
 :-)
 
 $file = readdir($open) != false
 
 You probably believe that PHP is going to magically know that you
 want this bit:
 readdir($open) != false
 to be done first
 


No, and I fixed that.  What I'm wondering about is why this

false !== ($dirhandle = opendir('letters'))

works, but this

($dirhandle = opendir('letters')) != false
does not

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] readdir() question

2006-08-15 Thread Richard Lynch
On Tue, August 15, 2006 5:56 pm, John Meyer wrote:
 Richard Lynch wrote:
 On Tue, August 15, 2006 12:04 pm, John Meyer wrote:
 I have a script to list the files in a directory:

 select name=letters
 ?php
 $open = opendir(.);
 while ($file = readdir($open) != false) {
 ?
 option value=?=$file??=$file?/option
 ?php
 }
 ?
 /select
 /form

 And all I am getting are 1s.  I think I'm doing it right, what is
 the
 disconnect?

 It's not a readdir question.  It's an Order of Operations question.
 :-)

 $file = readdir($open) != false

 You probably believe that PHP is going to magically know that you
 want this bit:
 readdir($open) != false
 to be done first



 No, and I fixed that.  What I'm wondering about is why this

 false !== ($dirhandle = opendir('letters'))

 works, but this

 ($dirhandle = opendir('letters')) != false
 does not

Do you really mean opendir() or do you mean readdir() ???

What value are you getting for $dirhandle?

echo it out and see what it is.

You also have != in one, and !== in the other.  Those aren't the same.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] readdir() question

2006-08-15 Thread John Meyer
Richard Lynch wrote:

 Do you really mean opendir() or do you mean readdir() ???


readdir().

The point is why do you need to put it as
!==

vs.
!=

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] readdir() question

2006-08-15 Thread Chris

John Meyer wrote:

Richard Lynch wrote:


Do you really mean opendir() or do you mean readdir() ???



readdir().

The point is why do you need to put it as
!==

vs.
!=



They mean different things.

!== means check the values are not the same AND check their types.

!= means check the values are not the same.

http://www.php.net/manual/en/language.operators.comparison.php

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php