• johnstewart

    (@johnstewart)


    I am trying now to prettify my PHP script references in this post: http://wordpress.org/support/topic/68468

    Basically, I want to be able to do a popup of an image, but in order to size the popup window appropriately, I need to check the image size before I do the popup.

    I don’t see any built-in WordPress functions that would do, so I’m trying to use the PHP function getimagesize().

    I first passed the absolute pathname on the server:

    /home/content/j/o/h/johnsgd/pics/gross/$filename

    And got an error. Then I tried a relative pathname from the theme’s directory (since that is where my PHP template file is and it seems to be referring to that as the base):

    ../../../pics/gross/$filename

    Then I tried dumping the pics inside a subdirectory of the theme directory:

    /images/gross/$filename

    In all cases I’m getting an error similar to this:

    Warning: getimagesize(/images/gross/DSCN6749.JPG): failed to open stream: No such file or directory in /home/content/j/o/h/johnsgd/html/wp-content/themes/almost-spring-hacked/gross.php on line 70

    Is there some secret sauce for accessing files directly via the PHP functions?

    thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Kafkaesqui

    (@kafkaesqui)

    Have you tried the (full) url to the image?

    Thread Starter johnstewart

    (@johnstewart)

    Kafkaesqui – I have not; it is my understanding that this only operates on local files. A URL would be a remote file (even if hosted on the same server).

    Would PHP somehow fetch the image via HTTP and then operate getimagesize? (I’m not being sarcastic; I’m a virgin to PHP even though I’ve coded in other languages quite a bit)

    thanks

    Kafkaesqui

    (@kafkaesqui)

    getimagesize() has accepted an url since PHP 4.0.5, according to the documentation:

    http://php.net/getimagesize

    I currently use getimagesize() in several scripts and do use the url to the image as the path or filename argument. I don’t believe it so much as “fetches” the image as it performs a http request that passes the info to it.

    Thread Starter johnstewart

    (@johnstewart)

    Right you are; sure makes the code a lot simpler, too!

    thanks!!

    davidchait

    (@davidchait)

    actually, that’s NASTY if you are using local images — an HTTP request PER image, for a file that’s sitting on your local disk?? nah. not the best approach, IMHO.

    the full-path method should work fine. as should getting the root dir of your wp install via php, concat wp-content onto that string, and then have /pics in wp-content so concat /pics/[filename] on the end. that’ll build an absolute path to the given file.

    /home/content/j/o/h/johnsgd/pics/gross/$filename
    hmmm. first, I assume that was in double quotes, not single quotes. 😉 second, I’m hoping you didn’t mean:
    /home/content/j/o/h/johnsgd/html/pics/gross/$filename
    third, if you meant the original, make sure permissions were set to allow access..

    -d

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Accessing files with PHP functions from WordPress’ is closed to new replies.