FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Help needed with images in php include files





woundedhealer
I succeeded in putting my banner in the top of one file using php include, but it hasn't worked out with others. I wanted to use this page as a template in different folders. I added the appropiate ../ to the file name but although the file is acknowledged, the images aren't registering. I've no problem with a text file include in the same file, it's just the images causing a problem.

The only PHP I know is how to include a file, so i can't even guess at the problem.

HELP!!!
AftershockVibe
The href path in the <a> element is relative to the page you are viewing.
If you make sure that is the case then that should fix your problem. If you want to use the header file from pages in different directories you'll need to make sure that the way to navigate to the images is the same or use an absolute path. (http://<whatever>/image.jpg>)
sonam
How I know it is not at possible to include images directly in the page.
include ("images/some_image.jpg"); cannot work. You must echo image. Also, if you want to put your template in any folder or subfolder then you can use $_SERVER['DOCUMENT_ROOT'] and this will allways looking for your images from root folder (public_html) not from folder where is template. Here is simple example:

Code:
<?php
$path = $_SERVER['DOCUMENT_ROOT'] . "/images/";
$image = ($path . "some_image.jpg");
echo "<img src=\"$image\" />";
?>

Sonam
imagefree
sonam wrote:
How I know it is not at possible to include images directly in the page.
include ("images/some_image.jpg"); cannot work. You must echo image. Also, if you want to put your template in any folder or subfolder then you can use $_SERVER['DOCUMENT_ROOT'] and this will allways looking for your images from root folder (public_html) not from folder where is template. Here is simple example:

Code:
<?php
$path = $_SERVER['DOCUMENT_ROOT'] . "/images/";
$image = ($path . "some_image.jpg");
echo "<img src=\"$image\" />";
?>

Sonam


one more thing!!! And i think its more is that files are included on the server, while the images are included (in the way sonam said) in the browser, so the link you give for images must be a proper hyperlink (whether relative or full ) that is accessible to outside world.
sonam
I am not sugest full hyperlink because loading time of images (especialy if is more then 100kb) is longer (in miliseconds Laughing ) then relative.
But, of course, he can use someting like:
Code:
$image = "http://www.some_host/images/some_image.jpg";


Sonam
woundedhealer
Thanks guys, I understand where I went wrong now. I had used php file include in another website ages ago with no problem. I've managed to find it and like you said, I had used the full hyperlink.

As for all your other information, I'm going to copy and paste it into dreamweaver so I can study it and try and make sense of it.

Anyone know of a really easy to read php tutorial that a dyslexic can make sense of? Eh?
woundedhealer
I've found some good PHP video tutorials which you can find here http://www.killerphp.com/videos/

He's a bit long-winded, but I think that could be a good thing because I find the information sinks in better.

I bought myself a new book yesterday, PHP and MySQL for Dynamic Web Sites, by Larry Ullman. It was the only book on the subject and a bit expensive, but I'm finding with a combinatin of the book and video tutorial it's all beginging to make sense.
Related topics
Site Nav Suggestions...
Help Needed Regarding CGI And Php
Do we support php include and/or SSI?
php script in php nuke - need help!
[Resolved] Object Orientated PHP errors
PHP include code problem
Php parsing error! Need help
Php Maximun Files Upload?
so, this is what I want to do... help needed
$_COOKIE and $_SESSION help needed!
Uplaoding images using php form :::: Help needed
Big Help needed .
[Help]Reading images from folder (permissions)
[help]Mysql & php problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.