help with include("name") - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help with include("name")

deusdeus Posts: 45Member
hello

i got this problem that i cannot solve, so i need help. i dont know how to explain exactly so i give the picture.

i got "photos" and "image" folder at root. also i have "header.php" file at root. inside photos folder i have "photos.php" file. inside header.php, it uses images from "image" folder and "photos.php" include "header.php" using php include function. but when i view photos.php file, all the images are not found.

is there any workaround to this problem? thanks in advance

Comments

  • JonathanJonathan Posts: 2,914Member
    : i got this problem that i cannot solve, so i need help. i dont know
    : how to explain exactly so i give the picture.
    :
    : i got "photos" and "image" folder at root. also i have "header.php"
    : file at root. inside photos folder i have "photos.php" file. inside
    : header.php, it uses images from "image" folder and "photos.php"
    : include "header.php" using php include function. but when i view
    : photos.php file, all the images are not found.
    :
    : is there any workaround to this problem? thanks in advance

    It sounds to me like you've just got your paths confused. Does photos.php look for photos in terms of the filesystem on the machine it executes on? Or does it just print out HTML code with image tags and then you see broken images on the page?

    In case you weren't sure, the paths to images in the HTML are relative to the URL the user has in their location bar when the script is invoked, not relative to the location of any file you include. And in the PHP I *think* that paths are relative to the script that was initially invoked and not includes too - maybe someone who uses PHP somewhat more than I can confirm that for you though. :-)

    Hope this helps,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • deusdeus Posts: 45Member
    : : i got this problem that i cannot solve, so i need help. i dont know
    : : how to explain exactly so i give the picture.
    : :
    : : i got "photos" and "image" folder at root. also i have "header.php"
    : : file at root. inside photos folder i have "photos.php" file. inside
    : : header.php, it uses images from "image" folder and "photos.php"
    : : include "header.php" using php include function. but when i view
    : : photos.php file, all the images are not found.
    : :
    : : is there any workaround to this problem? thanks in advance
    :
    : It sounds to me like you've just got your paths confused. Does photos.php look for photos in terms of the filesystem on the machine it executes on? Or does it just print out HTML code with image tags and then you see broken images on the page?
    :
    : In case you weren't sure, the paths to images in the HTML are relative to the URL the user has in their location bar when the script is invoked, not relative to the location of any file you include. And in the PHP I *think* that paths are relative to the script that was initially invoked and not includes too - maybe someone who uses PHP somewhat more than I can confirm that for you though. :-)
    :
    : Hope this helps,
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    ummm, now i got confused =p better i print out the sample code; i discard the ...

    in header.php;

    image


    in photos.php;

    <?php include('../header.php'); ?>
    something here


    i know the final photos.php result after the server has parse this file would be;

    image < ----- but of course no this folder doesn't exist

    something here


    absolute path works (image) , but i dont want to use it because i might change the directory afterwards. any ideas so i can still be using relative pathing? thanks

  • JonathanJonathan Posts: 2,914Member
    : ummm, now i got confused =p better i print out the sample code; i
    : discard the ...
    Providing example code often helps pinpoint the problem. :-)

    : in header.php;
    :
    : image
    :
    :
    : in photos.php;
    :
    : <?php include('../header.php'); ?>
    : something here
    :
    :
    : i know the final photos.php result after the server has parse this
    : file would be;
    :
    : image < ----- but of course no this folder
    : doesn't exist
    :
    : something here
    :
    :
    : absolute path works (image) , but i dont want
    : to use it because i might change the directory afterwards. any ideas
    : so i can still be using relative pathing? thanks

    OK, so going on what I said, the user asks for, say:-

    /image/photos.php

    And that is in their location bar, of course your domain is before it and so on. So the browser expects the HTML to be relative to photos.php. The file header.php is only invoked on the server, the browser never knows about it. So what you actually want:-

    in header.php;

    image


    As you are already are in the /image folder when you run photos.php. Or do you mean if you run:-

    /photo/photos.php

    And you want the image:-

    /images/pic.jpg

    In that case (no matter where header.php is) you'd do:-

    image

    Hope you get it now! :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • deusdeus Posts: 45Member
    : : ummm, now i got confused =p better i print out the sample code; i
    : : discard the ...
    : Providing example code often helps pinpoint the problem. :-)
    :
    : : in header.php;
    : :
    : : image
    : :
    : :
    : : in photos.php;
    : :
    : : <?php include('../header.php'); ?>
    : : something here
    : :
    : :
    : : i know the final photos.php result after the server has parse this
    : : file would be;
    : :
    : : image < ----- but of course no this folder
    : : doesn't exist
    : :
    : : something here
    : :
    : :
    : : absolute path works (image) , but i dont want
    : : to use it because i might change the directory afterwards. any ideas
    : : so i can still be using relative pathing? thanks
    :
    : OK, so going on what I said, the user asks for, say:-
    :
    : /image/photos.php
    :
    : And that is in their location bar, of course your domain is before it and so on. So the browser expects the HTML to be relative to photos.php. The file header.php is only invoked on the server, the browser never knows about it. So what you actually want:-
    :
    : in header.php;
    :
    : image
    :
    :
    : As you are already are in the /image folder when you run photos.php. Or do you mean if you run:-
    :
    : /photo/photos.php
    :
    : And you want the image:-
    :
    : /images/pic.jpg
    :
    : In that case (no matter where header.php is) you'd do:-
    :
    : image
    :
    : Hope you get it now! :-)
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    i got what you mean and i understand. it. but that's not exactly i want to know. it's not the image inside photo.php that cannt be found, it's in the header.php. and you got confuse with image and photo folder, they are different ones. sorry.

    [code]
    image
    -- picture1.jpg
    -- picture2.jpg
    photo
    -- photo.php
    index.php
    header.php
    [/code]

    ok, this is more clear. -- is the sub directory. so inside header.php file, i put [code] image [/code]

    ok now, i want to use the same header (header.php) through out the sites, no other copy. so for index.php, if i type in [code] <?php include('header.php'); ?> [/code] ... there picture will be displayed right?

    but how about if i want to use the same header for photo.php file, i've tried [code] <?php include('../header.php'); ?> [/code] but it doesnt work. notice that i dont type any other tag inside both index.php and photo.php files except the php include tag.

    sorry for the confusion i brought =p thanks again

  • JonathanJonathan Posts: 2,914Member
    : i got what you mean and i understand. it. but that's not exactly i want to know. it's not the image inside photo.php that cannt be found, it's in the header.php. and you got confuse with image and photo folder, they are different ones. sorry.
    :
    : [code]
    : image
    : -- picture1.jpg
    : -- picture2.jpg
    : photo
    : -- photo.php
    : index.php
    : header.php
    : [/code]
    :
    : ok, this is more clear. -- is the sub directory. so inside header.php file, i put [code] image [/code]
    :
    : ok now, i want to use the same header (header.php) through out the sites, no other copy. so for index.php, if i type in [code] <?php include('header.php'); ?> [/code] ... there picture will be displayed right?
    :
    : but how about if i want to use the same header for photo.php file, i've tried [code] <?php include('../header.php'); ?> [/code] but it doesnt work. notice that i dont type any other tag inside both index.php and photo.php files except the php include tag.
    :
    : sorry for the confusion i brought =p thanks again

    OK, I think you're going to need to use an absoloute path if you want to do this. I know you wanted to avoid that. On the other hand, there is nothing to stop you doing something like:-

    $imagesFolder = '/images';

    At the top of header.php and then using that throughout the script. At least then if you install it somewhere else you only need to change the absoloute path in one place. Of course you could also look at environment variables to see what the request path was and generate relative paths based upon that, but it's getting kinda convoluted then.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • deusdeus Posts: 45Member
    : : i got what you mean and i understand. it. but that's not exactly i want to know. it's not the image inside photo.php that cannt be found, it's in the header.php. and you got confuse with image and photo folder, they are different ones. sorry.
    : :
    : : [code]
    : : image
    : : -- picture1.jpg
    : : -- picture2.jpg
    : : photo
    : : -- photo.php
    : : index.php
    : : header.php
    : : [/code]
    : :
    : : ok, this is more clear. -- is the sub directory. so inside header.php file, i put [code] image [/code]
    : :
    : : ok now, i want to use the same header (header.php) through out the sites, no other copy. so for index.php, if i type in [code] <?php include('header.php'); ?> [/code] ... there picture will be displayed right?
    : :
    : : but how about if i want to use the same header for photo.php file, i've tried [code] <?php include('../header.php'); ?> [/code] but it doesnt work. notice that i dont type any other tag inside both index.php and photo.php files except the php include tag.
    : :
    : : sorry for the confusion i brought =p thanks again
    :
    : OK, I think you're going to need to use an absoloute path if you want to do this. I know you wanted to avoid that. On the other hand, there is nothing to stop you doing something like:-
    :
    : $imagesFolder = '/images';
    :
    : At the top of header.php and then using that throughout the script. At least then if you install it somewhere else you only need to change the absoloute path in one place. Of course you could also look at environment variables to see what the request path was and generate relative paths based upon that, but it's getting kinda convoluted then.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    well, i guess i have to use absolute pathing then, but your idea using the variables seems to be much more convinient. thanks for your help, jonathan
  • JonathanJonathan Posts: 2,914Member
    : well, i guess i have to use absolute pathing then, but your idea
    : using the variables seems to be much more convinient. thanks for
    : your help, jonathan
    Welcome. We got there in the end. ;-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • deusdeus Posts: 45Member
    : : well, i guess i have to use absolute pathing then, but your idea
    : : using the variables seems to be much more convinient. thanks for
    : : your help, jonathan
    : Welcome. We got there in the end. ;-)
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    yo, found an easy way;

    [code]
    You can fix this by inserting the following tag in the container in your
    header.php file:

    ;

    This tells the page that any relative URLs used on your pages will be prefixed with
    "http://yoursite.com/";, regardless of which subdirectory they're in.
    [/code]
  • JonathanJonathan Posts: 2,914Member
    : yo, found an easy way;
    :
    : [code]
    : You can fix this by inserting the following tag in the container in your
    : header.php file:
    :
    : ;
    :
    : This tells the page that any relative URLs used on your pages will be prefixed with
    : "http://yoursite.com/";, regardless of which subdirectory they're in.
    : [/code]

    Ah, never underestimate the client-side solution. ;-)

    Thanks for sharing,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.