Remote images in PHP
Posted: Tue Apr 01, 2003 5:11 am
I've written a small application to perform spell checking on a page, then display that page with misspelled words highlighted. The page that is checked is consequently displayed on a different server, so any page with relative image paths is not going to display correctly, and ideally I'd like it to, well, not do that.
What I need to do is the following, but I'm stuck and don't know how...
1) Grab the location of the page being checked. I.E. if http://www.somesite.com/dir1/dir2/page.htm was being checked, I'd need to have a variable with value http://www.somesite.com/dir1/dir2/ from that (so grabbing the folder the page is in and the url).
2) Construct an eregi_replace or preg_replace command that takes any img tag where the src does not start with http://, and add in the variable from 1.
So an image tag like <img src=http://www.somesite.com/dir1/dir2/image.gif> would remain unchanged, but <img src=image.gif> would be changed to <img src=http://www.somesite.com/dir1/dir2/image.gif>.
Any idea would be more than welcome!
What I need to do is the following, but I'm stuck and don't know how...
1) Grab the location of the page being checked. I.E. if http://www.somesite.com/dir1/dir2/page.htm was being checked, I'd need to have a variable with value http://www.somesite.com/dir1/dir2/ from that (so grabbing the folder the page is in and the url).
2) Construct an eregi_replace or preg_replace command that takes any img tag where the src does not start with http://, and add in the variable from 1.
So an image tag like <img src=http://www.somesite.com/dir1/dir2/image.gif> would remain unchanged, but <img src=image.gif> would be changed to <img src=http://www.somesite.com/dir1/dir2/image.gif>.
Any idea would be more than welcome!