...

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



bruceleejr
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:



<?php
include("/home/rootkbc1/public_html/halo2us/images/carbine.png");
?>


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.

Fou-Lu
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.

Keleth
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.

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

Keleth
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.

bruceleejr
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.

Keleth
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum