Jump to content

Problem with readfile()


hedgehog001

Recommended Posts

I'm currently working on a site that will be referencing pages from another site that will be only presented internally on a different webserver on the local LAN.

 

So in order to do this, I've been attempting to use readfile() functions to present the pages I need from the original site.

 

However, images presented from the original site seem to be unpredictable.

 

For example, on some pages, I can get them to present correctly on IE7 but they won't work with Firefox 2.X.

On other pages, I can't get the images to present at all.

 

In the case that the images fail, the page only outputs a ton of junk code to the page instead.

 

I'm simply trying to use the following code:

 

<?php readfile("http://servername.com/images/image.png"); ?>

 

I'm guessing that I'm missing some things but I'm trying to keep this as simple as possible.  Please help me as I've been looking for how to get this to work for the last 4 days and I can't figure out why it's not.

 

 

Link to comment
https://forums.phpfreaks.com/topic/111506-problem-with-readfile/
Share on other sites

You would need to show the context where you are using that code and outputting the image.

 

You cannot output image data directly on a web page that has other HTML on it (you can browse directly to a single image though). You must use an <img src="url_of_the_image"> tag for each image and when the "url_of_the_image" is requested by the browser, a proper Content-type: header for the image must be output before the image data.

Sorry, I've never tried anything like this before.

 

Here's the code I've been playing around with over the last couple of hours:

 

<table>
<tr>
<td>
<?php 
header("Content-Type: image/png");
$img = readfile("http://server.com/image.png"); 
echo "<img src=".$img." />";
?>
</td>
</tr>
</table>

 

I know this won't work, but hopefully it gives you a better idea of what I'm trying to do.

 

The problem here is that the webserver I'm attempting to pull from is not public so I can't simply populate the img tag with a URL as the client machine will not be able to resolve the location.

 

So I'm attempting to find a way for the PHP code to go out and pull the image from the remote web server first before presenting to the client machine. 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.