PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > dir_object->read() on different platform
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
dir_object->read() on different platform

Réponse
 
LinkBack Outils de la discussion
Vieux 18/09/2007, 05h31   #1
news.php.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut dir_object->read() on different platform

Hi! I have some text and JPEG files inside a directory like:
1992-7-11.txt
1992-7-11_pic1.jpg
2000-4-10.txt
2000-4-10_pic1.jpg
2004-5-2.txt
2004-5-2_pic1.jpg
On a Windows box (XP + Apache), if I do a dir_object->read() for the
directory, read() reads the files above "in order" (eg.
1992-7-11.txt...2000-4-10.txt...2004-5-2.txt) even the time stamps on these
files are different.
However, after I ftp them to a Linux box and load the php script from the
Linux box, the order is gone. The time stamps on those files on the Linux
box are the same since they were all ftp and cp at the same time.
Does anyone know why? Can anyone suggest a simple solution?

Thanks.
Davis
  Réponse avec citation
Vieux 18/09/2007, 05h58   #2
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dir_object->read() on different platform

news.php.net wrote:
> Hi! I have some text and JPEG files inside a directory like:
> 1992-7-11.txt
> 1992-7-11_pic1.jpg
> 2000-4-10.txt
> 2000-4-10_pic1.jpg
> 2004-5-2.txt
> 2004-5-2_pic1.jpg
> On a Windows box (XP + Apache), if I do a dir_object->read() for the
> directory, read() reads the files above "in order" (eg.
> 1992-7-11.txt...2000-4-10.txt...2004-5-2.txt) even the time stamps on these
> files are different.
> However, after I ftp them to a Linux box and load the php script from the
> Linux box, the order is gone. The time stamps on those files on the Linux
> box are the same since they were all ftp and cp at the same time.
> Does anyone know why? Can anyone suggest a simple solution?
>
> Thanks.
> Davis
>

Use glob() instead and then use sort() on the returned array.

That should put things back in order

<?php

$ar = glob('/dir/');
sort($ar);

# This should display the files in order
foreach ( $ar AS $file ) {
echo $file;
}

?>

Hope that s

Jim
  Réponse avec citation
Vieux 18/09/2007, 06h02   #3
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dir_object->read() on different platform

Jim Lucas wrote:
> news.php.net wrote:
>> Hi! I have some text and JPEG files inside a directory like:
>> 1992-7-11.txt
>> 1992-7-11_pic1.jpg
>> 2000-4-10.txt
>> 2000-4-10_pic1.jpg
>> 2004-5-2.txt
>> 2004-5-2_pic1.jpg
>> On a Windows box (XP + Apache), if I do a dir_object->read() for the
>> directory, read() reads the files above "in order" (eg.
>> 1992-7-11.txt...2000-4-10.txt...2004-5-2.txt) even the time stamps on
>> these files are different.
>> However, after I ftp them to a Linux box and load the php script from
>> the Linux box, the order is gone. The time stamps on those files on
>> the Linux box are the same since they were all ftp and cp at the same
>> time.
>> Does anyone know why? Can anyone suggest a simple solution?
>>
>> Thanks.
>> Davis

> Use glob() instead and then use sort() on the returned array.
>
> That should put things back in order
>
> <?php
>
> $ar = glob('/dir/');
> sort($ar);
>
> # This should display the files in order
> foreach ( $ar AS $file ) {
> echo $file;
> }
>
> ?>
>
> Hope that s
>
> Jim
>

forgot, you might need to use the extension, like so.
glob('/path/to/files/*.txt');

glob() does recognize '*' & '?' as multi & single char replacements.

Jim
  Réponse avec citation
Vieux 18/09/2007, 06h07   #4
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dir_object->read() on different platform

news.php.net wrote:
> Hi! I have some text and JPEG files inside a directory like:
> 1992-7-11.txt
> 1992-7-11_pic1.jpg
> 2000-4-10.txt
> 2000-4-10_pic1.jpg
> 2004-5-2.txt
> 2004-5-2_pic1.jpg
> On a Windows box (XP + Apache), if I do a dir_object->read() for the
> directory, read() reads the files above "in order" (eg.
> 1992-7-11.txt...2000-4-10.txt...2004-5-2.txt) even the time stamps on these
> files are different.
> However, after I ftp them to a Linux box and load the php script from the
> Linux box, the order is gone. The time stamps on those files on the Linux
> box are the same since they were all ftp and cp at the same time.
> Does anyone know why? Can anyone suggest a simple solution?
>
> Thanks.
> Davis
>

but, to explain why it happens, it going to be like describing the
differences between *nix and windows.

Simply put, internally, they store file information differently and by
doing this differently, they display the file list differently.

Also, *nix file names are case sensitive and windows is not. Be careful
with this one, it will bite you at some point.

Jim
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11917 seconds with 12 queries