Jump to content

Steve1

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Steve1's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the help, it's working now! I changed the first suggested bit of code to stop at krsort, as well as changing the $sortedimages as suggested. I then modified my existing code so I could get the timestamp and filename of the images into separate variables and it's now outputting exactly as I wanted, in descending order with newest image uploaded at the top: Such as; 1290370828 and House MD 1.jpg 1290370799 and Hugh Laurie - House.jpg 1290346142 and house.jpg Thanks.
  2. I did try an equal sign so it read: []= but it still didn't work. This has really confused me and I don't know what to try next. Does anyone else have any suggestions? Thanks
  3. Thanks for the help. If I enter the code that was provided, this error appears: Fatal error: Cannot use [] for reading "My/Directory/Here" on line 98. Line 98 is: $sortedimages[]$filetime => $image; I had a play about with it, but I just can't figure out what to do. Also, I did copy and paste the code above straight from my PHP file. Cheers
  4. The problem: I'm trying to create a page which outputs images from a folder which I have been able to do, but the problem I'm having is not being able to get the page to display the most recent image according to file modification date at the top. The first set of code below outputs the image timestamps in descending order, from newest to oldest which is what I want, but as soon as I change/add a couple lines of code (Shown in the second lot of code) to get the image file name along with the timestamp, the echoed list (timestamp and file names) gets muddled up in a random order. In short; As soon as the file names are retrieved with the timestamp, the list goes from being organised descendingly, to not. Show timestamp only code (1st lot of code): <?php //Open images directory $ignore = array("..","."); $dir = opendir("images1"); $images = array(); $sortedimages = array(); //List files in images directory while (($file = readdir($dir)) !== false) if (!in_array($file, $ignore)) $images[] = $file; foreach ($images as $image) { $filetime = filemtime("images1/$image"); $sortedimages[] = $filetime; } rsort($sortedimages); foreach ($sortedimages as $sorted) { //foreach ($sorted as $key => $value) //{ echo "$sorted<br/>"; } //} closedir($dir); ?> The show timestamp and file name code (2nd lot of code): <?php //Open images directory $ignore = array("..","."); $dir = opendir("images1"); $images = array(); $sortedimages = array(); //List files in images directory while (($file = readdir($dir)) !== false) if (!in_array($file, $ignore)) $images[] = $file; foreach ($images as $image) { $filetime = filemtime("images1/$image"); $sortedimages[] = array($filetime => $image); } rsort($sortedimages); foreach ($sortedimages as $sorted) { foreach ($sorted as $key => $value) { echo "$key and $value<br/>"; } } closedir($dir); ?> The changes made in the 2nd script from the 1st: //Changed: $sortedimages[] = $filetime; ---> $sortedimages[] = array($filetime => $image); //Included the previously commented out: foreach ($sorted as $key => $value) { } //Changed: echo "$sorted<br/>"; ---> echo "$key and $value<br/>"; Thanks for any help!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.