Announcement

Collapse
No announcement yet.

PHP filemtime

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP filemtime

    I am trying to extend the functionality of the Auto Scaled product images PHP with a test :

    "Is original images newer than thumbnail equivalent"

    Code:
    $sOriginalImageName = str_replace('\\','/', 'ProductImageFileName');
    $nScaledWidth = 150;
    $sThumbImageName = 'Thumbnails/t_' . basename($sOriginalImageName);
    if (filemtime('$sOriginalImageName')) >= (filemtime('$sThumbImageName')) {
    it is the if (filemtime) line causing the issue .. logic seems right but PHP n00b skills lacking the cut.

    I realise the filemtime is not ideal but intend to copy move files to force new creation time rather than use MD5# and create SEO iffy filenames.

    Any help greatly welcomed.


    Bikster
    SellerDeck Designs and Responsive Themes

    #2
    There also needs to be a file_exist test doesn't there as the thumb may not be be created


    Bikster
    SellerDeck Designs and Responsive Themes

    Comment


      #3
      I use MD5 in my commercial add-ons (and have a commercial version of Auto Product Images that uses it) because it's the only way I can find of detecting that an image is still the same as before. I use the source MD5 concatenated with the various parameters that make up the destination image (width, height, border colour, JPEG compression, etc).

      E.g. someone could replace the source image with a different (and older) image. Code based on filetimes or file exists would then skip the updated image and you'd have the wrong image remaining online.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Forgot to say that I tried other ways.

        1) Write image to a temp file and compare that with the existing image. Too slow because of too many disk writes.

        2) Maintain a table of created images and info about the source images that created them. Too much code to maintain. Table at risk of corruption / errors.

        3) MD5 based solution. Using for a few years now. MD5 computation doesn't take too long and is effective. Also, some of my add-ons allow you to set an option that includes the product image filename as part of the destination filename but I don't encourage it as the filenames are long enough as-is.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment

        Working...
        X