Quick PHP problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Deathblade
Forum Newbie
Posts: 11
Joined: Mon Oct 30, 2006 5:57 pm

Quick PHP problem...

Post by Deathblade »

Alright, so ive got a piece of HTML on site #1 that looks something like this:

Code: Select all

<img src='www.mysite.com/display.php?user=example'></img>
and i want it to load the image off of site #2 (http://www.mysite.com/display.php)

in display.php

there is this:

Code: Select all

<img src='www.mysitecom/images/1.gif'></img>
<img src='www.mysitecom/images/2.gif'></img>
<img src='www.mysitecom/images/3.gif'></img>
<img src='www.mysitecom/images/4.gif'></img>

four images. This works when display.php is a text file, as in all of the images load. However, when the four images are generated from display.php, it just produces a broken image. How can i get PHP to dynamically generate the HTML of four images that an external site can read as HTML?

I'm sorry if that was a bit confusing but anything helps! I'm really stuck here and just need a little push.

Thanks a lot

~Deathblade


And by the way i did get the <img src> to load up 4 images from a single file that had the source of all 4 of them in it. Surprised me, but it worked.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If your remote script is generating the <img> tags, file_get_contents() or a sibling can pull that textual data on your local server.
Deathblade
Forum Newbie
Posts: 11
Joined: Mon Oct 30, 2006 5:57 pm

Post by Deathblade »

i know. see the thing is, im trying to get it so somebody can just paste that one line of HTML on their site and have it load up the images. it cant use any PHP or anything, it has to just be that one line of HTML. is that even possible?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Not even remotely. It would require Javascript to generate more than a single image.
Deathblade
Forum Newbie
Posts: 11
Joined: Mon Oct 30, 2006 5:57 pm

Post by Deathblade »

damn. is there any other way of having the user paste html code that could dynamically load from PHP?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If they placed each image (and the url's were unique so the images weren't cached so readily.)
Deathblade
Forum Newbie
Posts: 11
Joined: Mon Oct 30, 2006 5:57 pm

Post by Deathblade »

okay...

so i made a PHP file that echos the HTML for an image source.

i got an HTML file and did an <img src='the php file i just made'></img>

but it just makes a broken image, and when i right click it says location: myphpfile

what am i doing wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It should return the binary image data that is to be displayed.
Deathblade
Forum Newbie
Posts: 11
Joined: Mon Oct 30, 2006 5:57 pm

Post by Deathblade »

all it has is a broken image whose source is my php file. how would i find the binary?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Since it's returning an image tag, it should use the URL that it has.
Deathblade
Forum Newbie
Posts: 11
Joined: Mon Oct 30, 2006 5:57 pm

Post by Deathblade »

feyd wrote:Since it's returning an image tag, it should use the URL that it has.

well...that explains it all? anybody other than feyd want to help me out?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you'll find if you do a bit of searching around for the things he's mentioned you'll easily find your solution..

anyways, hint readfile()
Deathblade
Forum Newbie
Posts: 11
Joined: Mon Oct 30, 2006 5:57 pm

Post by Deathblade »

it has to be able to run off of a server that doesnt support PHP. only reads it from HTML like a text file to get the source for the images. i didnt explain this very well did i?

i made a great example in my other thread before it got locked...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Deathblade wrote:it has to be able to run off of a server that doesnt support PHP. only reads it from HTML like a text file to get the source for the images. i didnt explain this very well did i?

i made a great example in my other thread before it got locked...
So you have Server A (with PHP) pulling images from Server B (no PHP)?

If that's the case then that doesn't change anything. As Feyd mentioned, use file_get_contents() to pull the image from Server B, and then read the binary data with readfile()

Did I understand correctly?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Deathblade wrote:it has to be able to run off of a server that doesnt support PHP. only reads it from HTML like a text file to get the source for the images. i didnt explain this very well did i?

i made a great example in my other thread before it got locked...
The other thread was locked because those links could just as easily have been posted here.

Can you give us the context of the problem you are trying to solve? You may get some better solutions that way.
Post Reply