I made an array that renames newly uploaded files to 1 2 3 4 and so on, and then sorts them on the page, however file names like 10 or 1 are not in order.
How can i make the file name 01 02 03 04?
If I try to ad a 0 when it counts up, it doesnt work.
if (file_exists("blah/".$file.".tif"))
{
$file=$file + '01';
}
Sorting by file name is out of order when it reaches 10
Moderator: General Moderators
Re: Sorting by file name is out of order when it reaches 10
Read the manual page for the sort() function. There are different options that control how it sorts things. http://uk3.php.net/sort
Re: Sorting by file name is out of order when it reaches 10
I have looked at that page many times. I have used sort() and others that are listed on that page and still file names with 10 or 1 are out of order. i need to automatically insert a 0 before the number so it sorts correctly. My question is how to do this?
example: 1.jpg 2.jpg etc etc becomes 01.jpg 02.jpg etc
example: 1.jpg 2.jpg etc etc becomes 01.jpg 02.jpg etc
Re: Sorting by file name is out of order when it reaches 10
Hi,
without showing use your code for sorting the filenames you get, no one can helps you. We are not visionaries here.
without showing use your code for sorting the filenames you get, no one can helps you. We are not visionaries here.
Re: Sorting by file name is out of order when it reaches 10
If you want to sort files you can use a natsort() function.
However if you want to add '0' in head of your string you can use a concatenation operation.
and then sort data.
However if you want to add '0' in head of your string you can use a concatenation operation.
Code: Select all
<?
//...
$file = '0'.$file;
//...
?>