Forum Moderators: coopster

Message Too Old, No Replies

Includes not showing pictures (pathing)

         

hivelord

1:05 am on Jun 7, 2005 (gmt 0)

10+ Year Member



After searching for an hour, I guess I'll post my direct question.

I am currently creating a website as a first time PHP'er. I understand most of it, but am still having problems with linking pages correctly with include();

Main site is index.php, which links to my header.php and other php pages. When I include one of the files, it will show everything just fine, however it will not link to anything OTHER than the page.

My CSS is in a diffrerent folder as well as my images, and they are all broken.

After doing some research, I realized that PHP has some realy fits with paths, since it's server side, and doesn't like linking to directories until you show it exactly where to go. Here's an exerpt of my site code, trimmed down, to show you what I'm doing.

Thanks if you can help.

(Since the code function sucks on this site:)
---code---
include('header.php');

//The pages you wish to display
$pages = array(
'seeds' => 'seeds.php',
'contact'=> 'contact.php',
'forum'=> 'forum.php',
'support' => 'support.php'
);

//if the file exist, and is in the array it will display the file.
if(array_key_exists($_GET['id'], $pages))
{
foreach($pages as $id => $name) {
if($_GET['id'] == $id && file_exists($name)) {
include ($name);
}
}
}

else {

//We will now display the home page, but if some enters in the wrong name it will also display this page.
include("home.php");
}
---/code---

This file is on webroot. CSS is in /css and images are in/images.

The files included are php files with no php in them, and are straight html. The included files all link to seperate directoies mentioned above.

hivelord

8:31 am on Jun 7, 2005 (gmt 0)

10+ Year Member



No one can help? :(

Blackie

8:36 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Frankly I do not understand the question :-(
What is wrong? Paths to pictures?

Make sure you either use relative path from the php script location or absolute path of type 'http://domain.name/picture.jpg'

hivelord

8:53 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Let me explain.

Index.php ->

include('header.php');

//The pages you wish to display
$pages = array(
'seeds' => 'seeds.php',
'contact'=> 'contact.php',
'forum'=> 'forum.php',
'support' => 'support.php'
);

//if the file exist, and is in the array it will display the file.
if(array_key_exists($_GET['id'], $pages))
{
foreach($pages as $id => $name) {
if($_GET['id'] == $id && file_exists($name)) {
include ($name);
}
}
}

else {

//We will now display the home page, but if some enters in the wrong name it will also display this page.
include("home.php");
}

For instance let's look at header.php ->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="CSS/Level1_Verdana.css" rel="stylesheet" type="text/css" />
</head>
<body leftmargin="0" topmargin="10" marginwidth="0" marginheight="10">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="8"><img src="images/header.jpg" width="800" height="80" alt="Complete Web Services" /></td>
</tr>
<tr>
<td><img src="images/index_sub_left.jpg" width="213" height="30" alt="" /></td>
<td><img src="images/index_stretch.gif" width="37" height="30" alt="" /></td>
...etc

Now, the IMG tags should be showing their sources, but they are just showing broken links. I don't know the problem :(

Also, index.php and header.php are both on the webroot. The image files are under /images

[edited by: jatar_k at 4:40 pm (utc) on June 7, 2005]
[edit reason] no urls thanks [/edit]

Blackie

10:27 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Forbidden
You don't have permission to access /images/header.jpg on this server.

This is the reply I get from your server. Chmod the directory so that others can access it.

hivelord

10:31 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Try again.

hivelord

10:32 am on Jun 7, 2005 (gmt 0)

10+ Year Member



/images is at 766

Blackie

10:33 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Still the same :-(
chmod o+rx images from root

Blackie

10:34 am on Jun 7, 2005 (gmt 0)

10+ Year Member



now i lost your frontpage as well :-)

hivelord

10:43 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Lol crap. What is default for folders and files?

folders is 755?

hivelord

10:46 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Oh my god, all this time it's been permissions!

Thanks for walking me through it.

Blackie

11:07 am on Jun 7, 2005 (gmt 0)

10+ Year Member



he he, default for folders is 755 as you just noticed :-)

Enjoy you new pages, and please remove links to them here (before a moderator does) as its against webmasterworld TOS :-)

hivelord

11:18 am on Jun 7, 2005 (gmt 0)

10+ Year Member



I'm not sure how...

Blackie

1:14 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



It's probably too late... you can not change it after a period of time... nevermind, they'll do it themselves :-)