Help with some php code

SpeedieSpeedie Registered Users Posts: 173 Major grins
Another forum member Nimai very kindly shared some code here which picks a random image based on keyword. I was using it for a while and it worked fine until a few weeks ago when it started generating the following error:

Warning: fread() [function.fread]: Length parameter must be greater than 0. in
/home/mgpages/public_html/misc/smugmug-random-image.php on line 20

Warning: Cannot modify header information - headers already sent by (output
started at /home/mgpages/public_html/misc/smugmug-random-image.php:20) in
/home/mgpages/public_html/misc/smugmug-random-image.php on line 53

I'm not a php programmer and have no idea what would cause this. The odd thing is it still works fine for Nimai who's using it. Nimai hasn't yet had time to look in to this so I wondered if anyone else might have an idea? Many thanks.

Comments

  • voytekvoytek Registered Users Posts: 4 Beginner grinner
    edited February 24, 2008
    Speedie wrote:
    Another forum member Nimai very kindly shared some code here which picks a random image based on keyword. I was using it for a while and it worked fine until a few weeks ago when it started generating the following error:

    Warning: fread() [function.fread]: Length parameter must be greater than 0. in
    /home/mgpages/public_html/misc/smugmug-random-image.php on line 20

    Warning: Cannot modify header information - headers already sent by (output
    started at /home/mgpages/public_html/misc/smugmug-random-image.php:20) in
    /home/mgpages/public_html/misc/smugmug-random-image.php on line 53

    I'm not a php programmer and have no idea what would cause this. The odd thing is it still works fine for Nimai who's using it. Nimai hasn't yet had time to look in to this so I wondered if anyone else might have an idea? Many thanks.
    Seems like your cache file is likely 0 bytes and the fread call doesn't like that.

    I would change line 17 from:
    if( $cacheexists && ($cacheage < $cacheretention) ) {
    
    to:
    if( $cacheexists && ($cacheage < $cacheretention) && (filesize($cachefile) > 0)) {
    
    and see what happens...

    If that solves it, it'll likely solve your second error too, since the second error is only complaining because of the first error's output.
  • SpeedieSpeedie Registered Users Posts: 173 Major grins
    edited February 25, 2008
    Thanks for looking at this. I replaced the code and it got rid of the errors, but now the URL is just displayed in the browser window! See here.
  • SpeedieSpeedie Registered Users Posts: 173 Major grins
    edited February 25, 2008
    Just to add this is what happens in the Firefox browser. In IE, an empty image placeholder is shown.
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited February 25, 2008
    Speedie,

    I meant to reply yesterday but I didn't get a chance, the issue will be that the security changes have seen the addition of an ImageKey, Nimai will need to modify his script to work properly.

    CHeers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • SpeedieSpeedie Registered Users Posts: 173 Major grins
    edited February 25, 2008
    Thanks David, but the odd thing is it's still working fine for Nimai (on his SmugMug account). eg. here.
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited February 25, 2008
    Speedie wrote:
    Thanks David, but the odd thing is it's still working fine for Nimai (on his SmugMug account). eg. here.

    it will still work for oldimages prior to the security changes. :D
    David Parry
    SmugMug API Developer
    My Photos
  • SpeedieSpeedie Registered Users Posts: 173 Major grins
    edited February 25, 2008
    Ah ok, that explains it.
Sign In or Register to comment.