473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

order by file name readdir()

MZ
Hello!

I have written such function...

Unfortunately images are not sorted by filename and I don`t know why.

I have such files placed in subfolder:

2005_11_17_koncert_Riverisde_w_Poznaniu_1.jpg
2005_11_17_koncert_Riverisde_w_Poznaniu_2.jpg
2005_11_17_koncert_Riverisde_w_Poznaniu_3.jpg
2005_11_17_koncert_Riverisde_w_Poznaniu_4.jpg
2005_11_17_koncert_Riverisde_w_Poznaniu_5.jpg
2005_11_17_koncert_Riverisde_w_Poznaniu_6.jpg
2006_01_22_wizyta_Panstwa_Rakowskich.jpg
2006_01_22_wizyta_u_babci_Ali.jpg

Even if I replaced the file names into

a2005_11_17_koncert_Riverisde_w_Poznaniu_1.jpg
a2005_11_17_koncert_Riverisde_w_Poznaniu_2.jpg
a2005_11_17_koncert_Riverisde_w_Poznaniu_3.jpg
a2005_11_17_koncert_Riverisde_w_Poznaniu_4.jpg
a2005_11_17_koncert_Riverisde_w_Poznaniu_5.jpg
a2005_11_17_koncert_Riverisde_w_Poznaniu_6.jpg
b2006_01_22_wizyta_Panstwa_Rakowskich.jpg
b2006_01_22_wizyta_u_babci_Ali.jpg

it still gives me the wrong order.

Can you help me fixing it?
-------------------------------------------------------------------------------

function zczytaj_zdjecia_z_folderu($sciezka)
{

error_reporting(0);
$handle=opendir($sciezka);

if ($handle=="")
{
echo "<br>";
echo "<p align=\"center\">Brak plikow na dysku <b>".$sciezka."</b></p>";
$ilosc_zdjec_w_folderze=-1;
}
else
{
$licznik=0;
while (false !== ($file = readdir($handle)))
{
if ($file <"." && $file <"..")
{
$licznik++;
if ( (substr(strtoupper($file),strlen($file)-4,4)==".GIF") ||
(substr(strtoupper($file),strlen($file)-4,4)==".JPG") ||
(substr(strtoupper($file),strlen($file)-4,4)==".JPEG") ||
(substr(strtoupper($file),strlen($file)-4,4)==".BMP") ||
(substr(strtoupper($file),strlen($file)-4,4)==".PNG")
)
list($width, $height, $type, $attr) = getimagesize($sciezka.$file);

$item=$width/160;
$width_new=160;
$height_new=intval($height/$item);

if ($height_new>100)
{
$item=$height/100;
$height_new=100;
$width_new=intval($width/$item);
}
//najlepiej dobrany rozmiar to height=100; width=160;
{
?>
<a href="#" OnClick="funkcja('<?=$sciezka.$file; ?>');"><img
alt="<?=$file; ?>" src="<?=$sciezka."/".$file; ?>" border="1"
height="<?=$height_new; ?>" width="<?=$width_new; ?>"></a>
<?
if ($licznik==5) { echo "<br><br>"; $licznik=0;}
error_reporting(1);
// break;
}
}
else
{

}
}
}
error_reporting(1);

return (0);
}
----------------------------------------------------------------------------------------

Apr 15 '07 #1
4 44816
MZ schreef:
Unfortunately images are not sorted by filename and I don`t know why.
From: http://www.php.net/readdir
Returns the filename of the next file from the directory. The filenames
are returned in the order in which they are stored by the filesystem.

So you still have to add code that sorts the filenames by name..

eg:

$filenames = array();
while ($filename = readdir($dir)) {
$filenames[] = $filename;
}

sort($filenames);

foreach($filename in $filenames) {
echo $filename . '<br/>';
}

--
Tim Van Wassenhove <url:http://www.timvw.be/>
Apr 15 '07 #2
On Apr 15, 8:27 am, Tim Van Wassenhove <t...@users.sourceforge.net>
wrote:
MZ schreef:
Unfortunately images are not sorted by filename and I don`t know why.

From:http://www.php.net/readdir
Returns the filename of the next file from the directory. The filenames
are returned in the order in which they are stored by the filesystem.

So you still have to add code that sorts the filenames by name..

eg:

$filenames = array();
while ($filename = readdir($dir)) {
$filenames[] = $filename;

}

sort($filenames);

foreach($filename in $filenames) {
echo $filename . '<br/>';

}

--
Tim Van Wassenhove <url:http://www.timvw.be/>
Alternatively you can use scandir() and specify the sorting_order
parameter:

<http://www.php.net/scandir>

Apr 15 '07 #3
MZ

Uzytkownik "Tim Van Wassenhove" <ti***@users.sourceforge.netnapisal w
wiadomosci news:Lq******************************@scarlet.biz. ..
MZ schreef:
>Unfortunately images are not sorted by filename and I don`t know why.

From: http://www.php.net/readdir
Returns the filename of the next file from the directory. The filenames
are returned in the order in which they are stored by the filesystem.

So you still have to add code that sorts the filenames by name..

eg:

$filenames = array();
while ($filename = readdir($dir)) {
$filenames[] = $filename;
}

sort($filenames);

foreach($filename in $filenames) {
echo $filename . '<br/>';
}

Thank you very much for help..

There is little error in the code. It should be:

foreach($filenames in $file) {
echo $file . '<br/>';
}
Cheers, thanx, hugs
Marcin
Apr 15 '07 #4
MZ

U¿ytkownik "MZ" <ma**************@poczta.onet.plnapisa³ w wiadomo¶ci
news:ev**********@news.onet.pl...
>
Uzytkownik "Tim Van Wassenhove" <ti***@users.sourceforge.netnapisal w
wiadomosci news:Lq******************************@scarlet.biz. ..
>MZ schreef:
>>Unfortunately images are not sorted by filename and I don`t know why.

From: http://www.php.net/readdir
Returns the filename of the next file from the directory. The filenames
are returned in the order in which they are stored by the filesystem.

So you still have to add code that sorts the filenames by name..

eg:

$filenames = array();
while ($filename = readdir($dir)) {
$filenames[] = $filename;
}

sort($filenames);

foreach($filename in $filenames) {
echo $filename . '<br/>';
}


Thank you very much for help..

There is little error in the code. It should be:

foreach($filenames in $file) {
echo $file . '<br/>';
}
Cheers, thanx, hugs
Marcin
Sorry it should be::

foreach($filenames as $file)
{
echo $file . '<br/>';
}
Apr 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tor Rest | last post by:
This is the scenario: I have the following ZIP files in a directory. The numbers represent versions (the highest number is the latest version of the file). mercury001.zip mercury002.zip...
0
by: pepin_labulle | last post by:
I'm a newbie with XQuery and I'm trying to execute a query with Saxon. If I don't specify the XML source file name in the query, Saxon raises the following error :...
12
by: Mike Brashars | last post by:
Hi all, I have been searching for a week and am unable to find and example to "Populate picklist from directory and return file name". I have a php script that reads a log file and plots a...
1
by: davidgordon | last post by:
Hi, I'm using the FileOpenDialog API that everyone has told me about which is posted everywhere on this forum.....works like a dream. When I select a file I get the full path such as : ...
2
by: ironwall22z | last post by:
My goal is to write a program in C# that will take the Artist and Title of an MP3 file and change the name of the file to a concatenated combination of the two. In order to do this, I am trying to...
4
by: Kavi | last post by:
i have a input type <input STYLE=font-size:10px; type=file name=filePath size=60 > and i have a file name Federal police have issued accused terrorist Jack Thomas with a control order,...
3
by: santhosh_h_98 | last post by:
ostream& operator<<(ostream& o, const bdd& d) { I want to Print file name here. How can I get file name from o ? } void main() { bdd c(a,5,9) ; ofstream out("junk") ; out << c ; }
3
rajiv07
by: rajiv07 | last post by:
Hi to all, I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i...
0
by: WillChapman | last post by:
Hello charitable, I have a repetitive task that requires the user to go to a command prompt, navigate to a folder (usually deep in the system), and perform a syntax scan on a file (with an in-house...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.