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



[PHP] Readdir

2006-11-28 Thread Tom Chubb

What would be the best way to retrieve a list of files from an upload
folder that are called id where the extension could be .doc .txt or
.pdf
For example, I have a folder where people can upload a document and
the document is renamed as their user id. They can upload a PDF, DOC
or TXT file. They may wish to upload one of each. I am using
file_exists for each case, but is there an easier/tidier way of doing
it?
Thanks in advance,

Tom

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



RE: [PHP] Readdir

2006-11-28 Thread Vincent DUPONT

If you are working in pure PHP5 OOP, you could like to try the new SPL 
iterators.
see http://www.phpro.org/tutorials/Introduction-to-SPL.html#12


vincent

-Original Message-
From: Tom Chubb [mailto:[EMAIL PROTECTED]
Sent: Tue 28/11/2006 9:55
To: [php] PHP General List
Subject: [PHP] Readdir
 
What would be the best way to retrieve a list of files from an upload
folder that are called id where the extension could be .doc .txt or
.pdf
For example, I have a folder where people can upload a document and
the document is renamed as their user id. They can upload a PDF, DOC
or TXT file. They may wish to upload one of each. I am using
file_exists for each case, but is there an easier/tidier way of doing
it?
Thanks in advance,

Tom

-- 
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

2006-11-28 Thread Jochem Maas
Tom Chubb wrote:
 What would be the best way to retrieve a list of files from an upload
 folder that are called id where the extension could be .doc .txt or
 .pdf
 For example, I have a folder where people can upload a document and
 the document is renamed as their user id. They can upload a PDF, DOC
 or TXT file. They may wish to upload one of each. I am using
 file_exists for each case, but is there an easier/tidier way of doing
 it?
 Thanks in advance,
 
 Tom
 

try the glob() function, something like:

$id = getUserId();
foreach (glob(/path/to/user/files/$id.*) as $file) {
echo $file,br /;
}

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



Re: [PHP] Readdir

2006-11-28 Thread Børge Holen
something like this?

while ( gettype ( $file = @readdir (@opendir ( $dirname )) ) != boolean ){
check if correct extension, else - something completely else?
}

On Tuesday 28 November 2006 09:55, Tom Chubb wrote:
 What would be the best way to retrieve a list of files from an upload
 folder that are called id where the extension could be .doc .txt or
 .pdf
 For example, I have a folder where people can upload a document and
 the document is renamed as their user id. They can upload a PDF, DOC
 or TXT file. They may wish to upload one of each. I am using
 file_exists for each case, but is there an easier/tidier way of doing
 it?
 Thanks in advance,

 Tom

-- 
---
Børge
Kennel Arivene 
http://www.arivene.net
---

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



RE: [PHP] Readdir

2006-11-28 Thread Vincent DUPONT

yes, glob works well. 
here is an example to get pictures inside a folder ($path)

foreach(glob($path./*/{*.gif,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png}, GLOB_BRACE) as 
$filename){
$pics[]=$filename;
}

vincent
-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED]
Sent: Tue 28/11/2006 10:59
To: Tom Chubb
Cc: [php] PHP General List
Subject: Re: [PHP] Readdir
 
Tom Chubb wrote:
 What would be the best way to retrieve a list of files from an upload
 folder that are called id where the extension could be .doc .txt or
 .pdf
 For example, I have a folder where people can upload a document and
 the document is renamed as their user id. They can upload a PDF, DOC
 or TXT file. They may wish to upload one of each. I am using
 file_exists for each case, but is there an easier/tidier way of doing
 it?
 Thanks in advance,
 
 Tom
 

try the glob() function, something like:

$id = getUserId();
foreach (glob(/path/to/user/files/$id.*) as $file) {
echo $file,br /;
}

-- 
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

2006-11-28 Thread Tom Chubb

Thanks guys,
Looks like just what I need. Will test it out later.

Tom

On 28/11/06, Vincent DUPONT [EMAIL PROTECTED] wrote:


yes, glob works well.
here is an example to get pictures inside a folder ($path)

foreach(glob($path./*/{*.gif,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png}, GLOB_BRACE) as 
$filename){
   $pics[]=$filename;
   }

vincent
-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED]
Sent: Tue 28/11/2006 10:59
To: Tom Chubb
Cc: [php] PHP General List
Subject: Re: [PHP] Readdir

Tom Chubb wrote:
 What would be the best way to retrieve a list of files from an upload
 folder that are called id where the extension could be .doc .txt or
 .pdf
 For example, I have a folder where people can upload a document and
 the document is renamed as their user id. They can upload a PDF, DOC
 or TXT file. They may wish to upload one of each. I am using
 file_exists for each case, but is there an easier/tidier way of doing
 it?
 Thanks in advance,

 Tom


try the glob() function, something like:

$id = getUserId();
foreach (glob(/path/to/user/files/$id.*) as $file) {
   echo $file,br /;
}

--
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




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



Re: [PHP] Readdir

2006-11-28 Thread Tom Chubb

Got it working fine. Thanks Vincent and Jochem for pointing me in the
right direction. Here is the code I used in case anyone's
interested...

?php
foreach(glob($path.$id.{*.doc,*.pdf,*.txt,*.rtf},
GLOB_BRACE) as $filename) { $cvs[]=$filename; }

//Loop through the four possible extensions
$i = 0;
while ($i = 3) {
//Check there is a value before displaying
if(!empty($cvs[$i])) {
$cv = str_replace($path, , $cvs[$i]) ;
   echo a href=\$cvs[$i]\$cv/a;
echo br;
   }
echo \n;
$i++;
}
?

On 28/11/06, Tom Chubb [EMAIL PROTECTED] wrote:

Thanks guys,
Looks like just what I need. Will test it out later.

Tom

On 28/11/06, Vincent DUPONT [EMAIL PROTECTED] wrote:

 yes, glob works well.
 here is an example to get pictures inside a folder ($path)

 foreach(glob($path./*/{*.gif,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png}, GLOB_BRACE) 
as $filename){
$pics[]=$filename;
}

 vincent
 -Original Message-
 From: Jochem Maas [mailto:[EMAIL PROTECTED]
 Sent: Tue 28/11/2006 10:59
 To: Tom Chubb
 Cc: [php] PHP General List
 Subject: Re: [PHP] Readdir

 Tom Chubb wrote:
  What would be the best way to retrieve a list of files from an upload
  folder that are called id where the extension could be .doc .txt or
  .pdf
  For example, I have a folder where people can upload a document and
  the document is renamed as their user id. They can upload a PDF, DOC
  or TXT file. They may wish to upload one of each. I am using
  file_exists for each case, but is there an easier/tidier way of doing
  it?
  Thanks in advance,
 
  Tom
 

 try the glob() function, something like:

 $id = getUserId();
 foreach (glob(/path/to/user/files/$id.*) as $file) {
echo $file,br /;
 }

 --
 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





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



Re: [PHP] Readdir

2006-11-28 Thread Jochem Maas
Tom Chubb wrote:
 Got it working fine. Thanks Vincent and Jochem for pointing me in the
 right direction. Here is the code I used in case anyone's
 interested...
 
 ?php
 foreach(glob($path.$id.{*.doc,*.pdf,*.txt,*.rtf},
 GLOB_BRACE) as $filename) { $cvs[]=$filename; }
 
 //Loop through the four possible extensions
 $i = 0;
 while ($i = 3) {
 //Check there is a value before displaying

why? glob only finds things if they exist.
*looks* like a misunderstanding of GLOB_BRACE.

why 2 loops?

 if(!empty($cvs[$i])) {
$cv = str_replace($path, , $cvs[$i]) ;
echo a href=\$cvs[$i]\$cv/a;
 echo br;
}
 echo \n;
 $i++;

this shouldn't work. at least the links shouldn't work
unless the files are on a local disk (which is a web scenario is unlikely).

foreach(glob($path.$id.{*.doc,*.pdf,*.txt,*.rtf},GLOB_BRACE) as $f) {
echo 'a 
href=',makeFilePathIntoValidURL($f),'',basename($f),'/abr /';
}

// just a example/idea - I assume the 'id' files are accessible via the web
function makeFilePathIntoValidURL($f) {
if (!strpos($f, $_SERVER['DOCUMENT_ROOT']) === 0) return '#nolink';
return str_replace($_SERVER['DOCUMENT_ROOT'], $f);
}



 }
 ?
 
 On 28/11/06, Tom Chubb [EMAIL PROTECTED] wrote:
 Thanks guys,
 Looks like just what I need. Will test it out later.

 Tom

 On 28/11/06, Vincent DUPONT [EMAIL PROTECTED] wrote:
 
  yes, glob works well.
  here is an example to get pictures inside a folder ($path)
 
  foreach(glob($path./*/{*.gif,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png},
 GLOB_BRACE) as $filename){
 $pics[]=$filename;
 }
 
  vincent
  -Original Message-
  From: Jochem Maas [mailto:[EMAIL PROTECTED]
  Sent: Tue 28/11/2006 10:59
  To: Tom Chubb
  Cc: [php] PHP General List
  Subject: Re: [PHP] Readdir
 
  Tom Chubb wrote:
   What would be the best way to retrieve a list of files from an upload
   folder that are called id where the extension could be .doc .txt or
   .pdf
   For example, I have a folder where people can upload a document and
   the document is renamed as their user id. They can upload a PDF, DOC
   or TXT file. They may wish to upload one of each. I am using
   file_exists for each case, but is there an easier/tidier way of doing
   it?
   Thanks in advance,
  
   Tom
  
 
  try the glob() function, something like:
 
  $id = getUserId();
  foreach (glob(/path/to/user/files/$id.*) as $file) {
 echo $file,br /;
  }
 
  --
  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
 
 

 

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



[PHP] readdir

2006-09-15 Thread Toby Osbourn

I have been writing some code that visits each directory stored within one
directory in turn, pics a random image from it and displays that image.

I have the code working fine, apart from one small quirk that I can't really
understand.

In one version of the implementation, the directories appear to be getting
accessed in the order they are uploaded to / edited on the server starting
with the most recent upload/change - which is handy because it is what I
wanted.

But in another slightly different version of the same bit of code, it lists
them in some weird order that I can't fathom.

I suppose my question put simply is, what is the default ordering of
directories when PHP uses the readdir method? And is there anyway to force a
specific ordering to the directories before PHP searches down them?

Any help would be greatly appreciated.

Regards,

Toby


RE: [PHP] readdir

2006-09-15 Thread Brad Fuller
According to php.net, the readdir() function simply reads the contents of
the directory in the order which they are stored by the filesystem.

One way to force the order would be to loop through the contents of the
directory and store the directory names into an array, and use the functions
filemtime() and sort() to sort the array.

Hope that helps,

Brad

-Original Message-
From: Toby Osbourn [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 15, 2006 3:18 PM
To: php-general@lists.php.net
Subject: [PHP] readdir

I have been writing some code that visits each directory stored within one
directory in turn, pics a random image from it and displays that image.

I have the code working fine, apart from one small quirk that I can't really
understand.

In one version of the implementation, the directories appear to be getting
accessed in the order they are uploaded to / edited on the server starting
with the most recent upload/change - which is handy because it is what I
wanted.

But in another slightly different version of the same bit of code, it lists
them in some weird order that I can't fathom.

I suppose my question put simply is, what is the default ordering of
directories when PHP uses the readdir method? And is there anyway to force a
specific ordering to the directories before PHP searches down them?

Any help would be greatly appreciated.

Regards,

Toby

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



Re: [PHP] readdir

2006-09-15 Thread Richard Lynch
On Fri, September 15, 2006 2:18 pm, Toby Osbourn wrote:
 I suppose my question put simply is, what is the default ordering of
 directories when PHP uses the readdir method?

Whatever order the OS decides to use.

In practice, it's whatever is convenient for that particular file system.

So FAT, NFTS, Reiser, ext2, ext3, and so on could all behave differently.

For that matter, the OS could decide to randomize them, just for fun,
if it wanted to.

 And is there anyway to
 force a
 specific ordering to the directories before PHP searches down them?

Not with just opendir/readdir.

You could use exec() with ls to get them in various orders.
You could walk through and make an array and then sort.

-- 
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

2006-09-15 Thread Larry Garfield
On Friday 15 September 2006 14:18, Toby Osbourn wrote:

 I suppose my question put simply is, what is the default ordering of
 directories when PHP uses the readdir method? And is there anyway to force
 a specific ordering to the directories before PHP searches down them?

If you're on PHP 5, look at scandir().  It gives you an array of all of the 
files/directories in a given directory, which you can then sort with sort() 
or usort() or whatever.  If you're on PHP 4, there's a backport of it in 
PEAR::PHP_Compat that doesn't actually require the rest of PEAR to 
function. :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



[PHP] readdir filenames with accents issue

2006-09-08 Thread All U Want

Hi,

I'm creating a file browsing site but don't know how to list properly  
filenames containing accents  (french, spanish, etc). I've been  
browsing the archives but couldn't find a fix.


foreach ($files as $file) {
echo $file;
}

For example:
Filename: sábado-1.mov
Link: sábado-1.mov

I would appreciate any help.

Regards,
Luis.

PS - If it helps I'm working on OS X and PHP 4.4.1

--
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



[PHP] readdir problem with white spaces

2006-06-15 Thread Francisco Morales
Hello, I the following problem with readdir 

 

When I read the directory, if the file has more than one white spaces,
readdir only return me 

the file with one space ...

 

so if I have on the file system . ROAD 1  005.JPG  or ROAD1
0005.JPG  php readdir 

return me ROAD 1 005.JPG!!

 

while ($file = readdir ($dirlist))

   {

   if ($file != '.'  $file != '..')

   {   echo FILE: $filebrbr;  - ROAD 1 005.JPG

}

 

-rw-rw-r--  1 seaquist edi  125352 jun 15 12:06 ROAD 1 001.JPG

-rw-rw-r--  1 seaquist edi  157365 jun 15 12:06 ROAD 1 002.JPG

-rw-rw-r--  1 seaquist edi  115891 jun 15 12:07 ROAD 1 004.JPG

-rw-rw-r--  1 seaquist edi  135876 jun 15 12:07 ROAD 1 005.JPG

-rw-rw-r--  1 seaquist edi  103983 jun 15 12:07 ROAD 2  003.JPG

-rw-rw-r--  1 seaquist edi   92410 jun 15 12:07 ROAD 2  006.JPG

-rw-rw-r--  1 seaquist edi   75342 jun 15 12:07 ROAD 3  002.JPG

 

How can I fix this?

 

Thanks a lot

 


Key fingerprint = A232 A22F AEF0 1988 6ACB  99AF A18F A220 BD2E 8CD8

 



RE: [PHP] readdir problem with white spaces

2006-06-15 Thread Jay Blanchard
[snip]

When I read the directory, if the file has more than one white spaces,
readdir only return me 

the file with one space ...

 

so if I have on the file system . ROAD 1  005.JPG  or ROAD1
0005.JPG  php readdir 

return me ROAD 1 005.JPG!!
[/snip]


Additional white space is typically ignored in programming languages
that are built to deal with strings, but you may be able to count the
string length and/or use regex to make sure that the white space
remains.
 

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



[PHP] readdir and mime types

2005-11-22 Thread Graham Cossey
I'm attempting to read a list of files in a directory using readdir()
but am having problems with mpeg files not seemingly being read.

Cope snippet:

$count = 0;
while (false !== ($file = readdir($open_dir)))
{
if ($file != '.'  $file != '..')
{
if (file_exists($VID_DIR/$file))
{
$count++;

$count counts any 'avi' files but not 'mpg' files.

Any suggestions much apreciated.

--
Graham

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



RE: [PHP] readdir and mime types

2005-11-22 Thread Jay Blanchard
[snip]
I'm attempting to read a list of files in a directory using readdir()
but am having problems with mpeg files not seemingly being read.

Cope snippet:

$count = 0;
while (false !== ($file = readdir($open_dir)))
{
if ($file != '.'  $file != '..')
{
if (file_exists($VID_DIR/$file))
{
$count++;

$count counts any 'avi' files but not 'mpg' files.
[/snip]

Without seeing the rest of the code I am going to assume that $open_dir is
the handle for the directory the files are in. Given that, why would you
specify a directory in your file_exists function? I am unsure why
file_exists would be necessary at this point. Eliminate that condition and
see what the results are

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



Re: [PHP] readdir and mime types

2005-11-22 Thread Graham Cossey
On 11/22/05, Jay Blanchard [EMAIL PROTECTED] wrote:
 [snip]
 I'm attempting to read a list of files in a directory using readdir()
 but am having problems with mpeg files not seemingly being read.

 Cope snippet:

 $count = 0;
 while (false !== ($file = readdir($open_dir)))
 {
 if ($file != '.'  $file != '..')
 {
 if (file_exists($VID_DIR/$file))
 {
 $count++;

 $count counts any 'avi' files but not 'mpg' files.
 [/snip]

 Without seeing the rest of the code I am going to assume that $open_dir is
 the handle for the directory the files are in. Given that, why would you
 specify a directory in your file_exists function? I am unsure why
 file_exists would be necessary at this point. Eliminate that condition and
 see what the results are

Yes $open_dir is the handle from opendir().

The file_exists is simply checking for an associated file elsewhere as
I'm looking for video files and thumbnails.

As I said, this works fine for avi suffixed files but not mpg or mpeg
suffixed files.

--
Graham

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



RE: [PHP] readdir and mime types

2005-11-22 Thread Jay Blanchard
[snip]
Yes $open_dir is the handle from opendir().

The file_exists is simply checking for an associated file elsewhere as
I'm looking for video files and thumbnails.

As I said, this works fine for avi suffixed files but not mpg or mpeg
suffixed files.
[/snip]

Make sure to always hit reply-all, or the e-mail will not go back to the
list.

If file exists is looking for an associated files is it probable that the
.mpg files do not have one associated with it in the other directory?

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



Re: [PHP] readdir and mime types

2005-11-22 Thread Graham Cossey
[snip]
 Make sure to always hit reply-all, or the e-mail will not go back to the
 list.

Yep, realised that after hitting 'send'. :-(

 If file exists is looking for an associated files is it probable that the
 .mpg files do not have one associated with it in the other directory?

It is probable, that's why the check is there, but in this case the
associated file(s) definitely does exist. If I simply change the file
extensions from mpg to avi the script works.


--
Graham

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



Re: [PHP] readdir and mime types

2005-11-22 Thread David Grant
Graham,

Is safe mode enabled in your config file?  If safe mode is on, PHP will
check the file to ensure it is owned by the same user executing the
script.  If this condition fails, file_exists() will not work on the file.

http://php.net/file_exists
http://php.net/manual/en/features.safe-mode.php

Cheers,

David Grant

Graham Cossey wrote:
 [snip]
 Make sure to always hit reply-all, or the e-mail will not go back to the
 list.
 
 Yep, realised that after hitting 'send'. :-(
 
 If file exists is looking for an associated files is it probable that the
 .mpg files do not have one associated with it in the other directory?
 
 It is probable, that's why the check is there, but in this case the
 associated file(s) definitely does exist. If I simply change the file
 extensions from mpg to avi the script works.
 
 
 --
 Graham
 

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



RE: [PHP] readdir and mime types

2005-11-22 Thread Jay Blanchard
[snip]
 If file exists is looking for an associated files is it probable that the
 .mpg files do not have one associated with it in the other directory?

It is probable, that's why the check is there, but in this case the
associated file(s) definitely does exist. If I simply change the file
extensions from mpg to avi the script works.
[/snip]

Try this simple example and see what is output...

if ($handle = opendir('/path/to/files')) {
   while (false !== ($file = readdir($handle))) {
   if ($file != .  $file != ..) {
   echo $file\n;
   }
   }
   closedir($handle);
}

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



Re: [PHP] readdir and mime types

2005-11-22 Thread Graham Cossey
[snip all]

OK, of course it's my fault !!  :o

My directory variables are using relative paths and I was trying to
access the parent directory from the sub-directory but not using '..'

Sorry.

Thanks for your help.

--
Graham

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



Re: [PHP] readdir and mime types

2005-11-22 Thread Richard Lynch
On Tue, November 22, 2005 8:23 am, Graham Cossey wrote:
 I'm attempting to read a list of files in a directory using readdir()
 but am having problems with mpeg files not seemingly being read.

 Cope snippet:

   $count = 0;
   while (false !== ($file = readdir($open_dir)))
   {
 if ($file != '.'  $file != '..')
 {
 if (file_exists($VID_DIR/$file))

What is $VID_DIR?

What directory is $open_dir pointing to?

Dollar gets you 10 that at least one of them is not what you think it is.

 {
   $count++;

 $count counts any 'avi' files but not 'mpg' files.

 Any suggestions much apreciated.

It's also remotely possible that your 'mpg' files are not readable by
the PHP user or something weird like that...  Though I don't THINK you
can do this, it's possible that your OS allows it...

-- 
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() and files with numbers

2005-09-14 Thread sub
I'm having a really weird problem. My code works, unless the images start with 
a number, then I get a 500 error. If they start with a letter it's fine. 

some example of problem files:
178_image.jpg
0005396C.jpg

the whole reason I wrote this code was so that I wouldn't have to rename all my 
files to pic1, pic2, etc...

What I find truely crazy, is that I can rename 178_image.jpg to 
a178_image.jpg and everything is fine.  How can I work with file names that 
start with numbers?

**
// the thumbnail page (new card and new paragraph)
echo( card id='thumbs'\n );
echo( p\n );

// $path is the gender group (lesbian, gays, etc...)
// $group is the model group (matt, rick, nurses, etc...)

if ($handle = opendir(galleries/$path/$group/pics/thumb/)) 
{
   $b=0;
   while (false !== ($file[$b] = readdir($handle))) 
   {
   $b++;
   }
   closedir($handle);
}

// Create the thumbnail table
// The table should be 3x3
echo( table columns='3'\n);

// $a is the counter w/ values 1-9
// $i is row number w/ values 1-3
// $j is column number w/ valuse 1-3
// $q is the counter for the files read from the thumbnail directory

$q=0;
for( $i=1, $a=1; $i=3; $i++)
{
 echo( tr\n);
 for( $j=1; $j=3; $a++, $j++)
 {
  if($file[$q]==. || $file[$q]==..)
  {
   $q++;
  }
  echo( tda href='#$file[$q]'img 
src='galleries/$path/$group/pics/thumb/$file[$q]' alt='thumb$a'//a/td\n);
  $q++;
 }
 echo( /tr\n);
}
// End the table
echo( /table\n);

// End the paragraph and card
echo( /p\n );
echo( /card\n );

// Loop creating 9 cards for the pics 
for( $x=1, $q=0; $x=9; $q++, $x++)
{
 
 if($file[$q]==. || $file[$q]==..)
 {
  $q++;
 }

 // the thumbnail page (new card and new paragraph)
 echo( card id='$file[$q]'\n );
 echo( p\n );
 

 echo( img src=\galleries/$path/$group/pics/$file[$q]\ alt='pic$x'/\n); 

 // End the paragraph and card
 echo( /p\n );
 echo( /card\n );


Andrew Darrow
Kronos1 Productions
www.pudlz.com



Re: [PHP] readdir behavior I cannot understand

2004-09-20 Thread Jason Wong
On Monday 20 September 2004 11:44, Jason FB wrote:

 Hereis my script, I copied and pasted Example 1 from this page:

 http://us4.php.net/manual/en/function.readdir.php


 You will see that the only way that I changed I initialize two
 variables at the very top that set the directory of the directory to
 open. The script should read the contents of the directory and print
 them to the resulting page.

 Instead, it returns a the following parse error

 Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in
 /Users/jason/Sites/images_exotic/REDESIGN2 FALL
 04/admin/check_set_local.php on line 4

If you did literally copy and pasted the code from the manual then that's 
probably what's causing the problem. Sometimes c  p from say a browser can 
introduce spurious characters into your code (usually the TAB character I 
think). Try *typing* in the code.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
If the master dies and the disciple grieves, the lives of both have
been wasted.
*/

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



[PHP] readdir behavior I cannot understand

2004-09-19 Thread Jason FB
PHP General List,
I am trying to read the contents of a directory on a server and 
perform imagemagick operations on each JPG found inside the 
directory. The area where I am stuck currently is not the image 
manipulation but the PHP function readdir().

Can anyone explain why I am having this behavior with PHP using the 
scripts out of the manual pages for readdir()

Hereis my script, I copied and pasted Example 1 from this page:
http://us4.php.net/manual/en/function.readdir.php
You will see that the only way that I changed I initialize two 
variables at the very top that set the directory of the directory to 
open. The script should read the contents of the directory and print 
them to the resulting page.

Instead, it returns a the following parse error
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in 
/Users/jason/Sites/images_exotic/REDESIGN2 FALL 
04/admin/check_set_local.php on line 4

I see this PHP behavior on both Windows Server running PHP 4.3.2 and 
on my own Mac (OS X client) running apache as a Personal Web 
Sharing PHP version 4.3.6

Any help is appreciated.  The contents of the script which I cannot 
get the parse error out of is below.

On this vein, can anyone tell me a succinct explanation of the 
bang-equal-equal (!==) operator in contrast to the bang-equal (!=) 
operator?

I've never seen that before, is it borrowed from other languages? I 
do not remember it from when I was learning C++.

Thanks.
-JFB-

?php
// Note that !== did not exist until 4.0.0-RC2
$root_dir = /Users/jason/Sites/;
$folder_on_server test;
if ($handle = opendir($root_dir . $folder_on_server)) {
echo Directory handle: $handle\n;
echo Files:\n;
 /* This is the correct way to loop over the directory. */
 while (false !== ($file = readdir($handle))) {
echo $file\n;
}
 closedir($handle);
 }
?




[PHP] readdir and opendir

2004-05-10 Thread Vincent DUPONT
Simple question : do readdir and opendir support opening HTTP urls ??

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



[PHP] readdir() output question

2002-12-13 Thread RClark
Hello all!

Ok, I have a readdir() reading pictures files from a directory. But now I
want to output them into a html table, say 5 across the top row, then 5 the
next row, etc. What I cant figure out is how to make this happen. Right now,
I am not reading the files into an array. Should I do this and then create a
while loop?

Thanks,
Ron Clark



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




Re: [PHP] readdir() output question

2002-12-13 Thread Matt Vos
$img_count = 0;
echo(
table
tr
  td colspan=5My Images/td):

(loop through filenames)
{
if (($img_count % 5) == 0) echo(
/trtr);
echo(
tdimg_src=\$filename\/td);
$img_count = $img_count + 1;
}
while (($img_count % 5) != 0)
{
echo(
tdnbsp;/td);
}
echo(
/tr
/table)


Matt
RClark [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hello all!

 Ok, I have a readdir() reading pictures files from a directory. But now I
 want to output them into a html table, say 5 across the top row, then 5
the
 next row, etc. What I cant figure out is how to make this happen. Right
now,
 I am not reading the files into an array. Should I do this and then create
a
 while loop?

 Thanks,
 Ron Clark



 --
 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




[PHP] Readdir

2002-08-01 Thread msmecca

New To Php so please bear with me... :)

I used the readdir function to read the files listed on a Apache server. And
it worked fine. Now I would like to be able to get the files the php code
returns, to be links. Where the user can click the file and download it. Also
for the files to sit within a table or at least look neat on the page.
http://www.optimus7.com/findme.php is the result I get from the php code
below. Help!

?php
if ($handle = opendir('/my/directory')) {
echo Directory handle: $handle\n;
echo Files:\n;



while (false !== ($file = readdir($handle))) { 
echo $file\n;
}

  
closedir($handle); 
}
?

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




RE: [PHP] Readdir

2002-08-01 Thread Matt Schroebel

 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
 Sent: Thursday, August 01, 2002 2:54 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Readdir
 
 New To Php so please bear with me... :)
 
 I used the readdir function to read the files listed on a 
 Apache server. And
 it worked fine. Now I would like to be able to get the files 
 the php code
 returns, to be links. Where the user can click the file and 
 download it. Also
 for the files to sit within a table or at least look neat on the page.
 http://www.optimus7.com/findme.php is the result I get from 
 the php code
 below. Help!
 
 ?php
 if ($handle = opendir('/my/directory')) {
 echo Directory handle: $handle\n;
 echo Files:\n;
 
 
 
 while (false !== ($file = readdir($handle))) { 
 echo $file\n;
 }
 
   
 closedir($handle); 
 }
 ?

Change your echo stmt to something like:

echo a href=\$file\$file/abr\n;

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




Re: [PHP] Readdir

2002-08-01 Thread Nicole Lallande

Change:

echo $file\n;

to:

echo a href='$file'$file/a\n;
Note the nested quotes -- outer quotes - , inner quotes (around $file) 
single - '

Best,

Nicole

[EMAIL PROTECTED] wrote:

New To Php so please bear with me... :)

I used the readdir function to read the files listed on a Apache server. And
it worked fine. Now I would like to be able to get the files the php code
returns, to be links. Where the user can click the file and download it. Also
for the files to sit within a table or at least look neat on the page.
http://www.optimus7.com/findme.php is the result I get from the php code
below. Help!

?php
if ($handle = opendir('/my/directory')) {
echo Directory handle: $handle\n;
echo Files:\n;



while (false !== ($file = readdir($handle))) { 
echo $file\n;
}

  
closedir($handle); 
}
?


-- 

Nicole Lallande
[EMAIL PROTECTED]
760.753.6766





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




Re: [PHP] Readdir

2002-08-01 Thread Jason Wong

On Friday 02 August 2002 02:53, [EMAIL PROTECTED] wrote:
 New To Php so please bear with me... :)

 I used the readdir function to read the files listed on a Apache server.
 And it worked fine. 

 http://www.optimus7.com/findme.php is the result I get from the php
 code below. Help!

 ?php
 if ($handle = opendir('/my/directory')) {
 echo Directory handle: $handle\n;
 echo Files:\n;



 while (false !== ($file = readdir($handle))) {
 echo $file\n;
 }


 closedir($handle);
 }
 ?

1) If you don't want the parent directory (..) and current directory (.) to 
appear you should follow the example(s) in the manual.

2) In your while loop you can do something like:

   while (false !== ($file = readdir($handle))) {
 $file_array[] = $file;
   }

This will put all your files into an array $file_array, which you can then use 
foreach() to loop through each item and display neatly.

 Now I would like to be able to get the files the php
 code returns, to be links. Where the user can click the file and download
 it. Also for the files to sit within a table or at least look neat on the
 page.

These are basic HTML issues which presumably you should know the answer to.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Alimony is the high cost of leaving.
*/


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




Re: [PHP] Readdir

2002-08-01 Thread Danny wall

?php
if ($handle = opendir('/my/directory')) {
 echo Directory handle: $handle\n;
 echo Files:\n;



 while (false !== ($file = readdir($handle))) {
 echo $file\n;
 }

Everything is good, you just to make a slight addition to your echo.

echo a href=\$file\$file/aP

-Danny
You are stuupid
Dexter of Dexter's Labratory

Yeah, I watch Dexter, you got a problem with that! :-)

_
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


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