SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image from File List

    Hi all,

    I want to display an image from a folder, which all have names as the Unix timestamp of when they were uploaded. So, I thought that PHP could scan the directory they are uploaded in, and find every image. But I then realised with lots of images, this could take some time. The next idea I had was finding out the current timestamp, and then using a while loop display the latest then images to be uploaded (which would be the ten nearest the current time stamp). My question is, would the less than operator know that only the ten last images existed, or would it look for one less?

    The other problem I thought off, is how can PHP actively search the directory, and then pass back both the current image, and work out which ten should be displayed?

    I did think of having it find the first ten, by seeing if it returned anything at all, but this also seems liek a lot of work!

    Which is going to be the most effective method of doing what I want, or is there another method that I can't seem to think of!

  2. #2
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you need to run a script to find the files within a directory each time you need to get the latest file then, yes, it will be inefficient.

    What you need todo is store stats of the latest added files in some sort of data structure.

    1. You can create a cron job or a programmed trigger to update a database or a local file with stats on the latest file.

    PHP Code:
    $files scandir('./files');
    array_multisort($files,SORT_NUMERIC);
    foreach(
    $files as $f) {
        if(
    $f=='.' || $f=='..' || empty($f)) continue;

        
    //..add to the database

    2. Check out the PHP glob function to match specific files.
    I can't believe I ate the whole thing


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •