View Full Version : How do I display images with the include function?

06-27-2010, 12:58 AM
I am trying to display an image via php include function outside of the root folder of where the php code is.

The code is:


The page with this is in /home/rootkbc1/public_html/mujak/home.php

So I am trying to get out of the "mujak" directory & into the halo2us directory.

This code seems to be display a bunch of machine code, meaning its displaying the file but does not know how to interpret it.

Something with header function~? Just read on it, don't know if this has anything to do with it.

06-27-2010, 02:53 AM
You are aware that an image cannot actually be displayed with PHP?
If your intent is to serve it, then yes just push a content type for the image. This script would then become the source for your img tag. This is a waste though since the include is just an image with no dynamic data, so just use the png for your img src instead.

06-27-2010, 06:11 AM
A key thing to remember: PHP is a server side language. It processes data is given, and feeds back text. You format that text as you see fit: html, xml, javascript, etc. But at the end, PHP does nothing on the users end.

06-27-2010, 06:34 AM
Okay well, what is a good way to display an image outside of the root with php~???

06-27-2010, 07:11 AM
You don't display images with PHP... if you're building a webpage, you display images with HTML. So if you mean how do you display images outside the website's directory, you can't. As with any website, you can only display images accessible by the web.

06-27-2010, 07:47 AM
Are you serious~~!!! I was sure there was something you could use to access an image in a different directory outside its own.

06-27-2010, 08:09 AM
Again... PHP is a server side processing language. It doesn't do magic. It feeds text back to the user, and based on how you define that, it can be HTML, it can be Javascript, it can be XML, etc.

Now, with HTML, if the image is in another folder that is also accessible to the web (a different domain, a different subdomain, a subfolder), you can access it, like other images on the web. If its not, you can't.

Now, you could write a PHP script that reads an image, and generates a temporary file in the websites folder. But that would basically be putting an image into the websites folder and linking to it.